r - 与 ShinyApp 密谋?
问题描述
编辑:已解决。
我不确定问题出在哪里,但我猜是关于 Rstudio。当我将应用程序上传到https://shinyapps.io/时,它可以工作了!
我正在尝试用一个闪亮的应用程序渲染一个情节对象,
我在网上阅读了很多查询,其中大部分是关于使用“renderPlotly”而不是“renderPlot”,但不知何故我的情节没有显示。
当我尝试使用 ggplot 时,效果很好。
我究竟做错了什么?
感谢您的帮助,附上代码:
library("shiny")
library("plotly")
library("shinydashboard")
ui <- dashboardPage(dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(plotlyOutput("plot1",height = 250)),
box(
title = "Controls",
sliderInput("slider", "Slider Value:", 1, 10, 5)
)
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlotly({
clusters = my_classifier(k=input$slider, data=df)
results_df = cbind(df,as.factor(clusters))
colnames(results_df) = c("x","y","z","color")
plot_ly(data=results_df, x=~x, y=~y, z=~z,
type="scatter3d", mode="markers", color=~color)
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
该示例不完整并且有几个问题。如果我们排除不完整的数据分析部分并将其替换为随机测试数据,它在技术上是有效的:
library("shiny")
library("plotly")
library("shinydashboard")
ui <- dashboardPage(dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(plotlyOutput("plot1",height = 250)),
box(
title = "Controls",
sliderInput("slider", "Slider Value:", 1, 10, 5)
)
)
)
)
server <- function(input, output) {
output$plot1 <- renderPlotly({
#clusters = my_classifier(k=input$slider, data=df)
#results_df = cbind(df,as.factor(clusters))
#colnames(results_df) = c("x","y","z","color")
## random test data set
results_df <- data.frame(x=runif(10), y=runif(10), z=rnorm(10), color=1:10)
plot_ly(data=results_df, x=~x, y=~y, z=~z,
type="scatter3d", mode="markers", color=~color)
})
}
# Run the application
shinyApp(ui = ui, server = server)
所以我的建议是先修复shiny之外的数据分析部分,当一切正常时,将各个部分放在一起。
推荐阅读
- reactjs - react-beautiful-dnd 拖放不起作用
- c - 64位系统中结构的内存分配
- android - 是否可以在 Flutter 的 Widget 中创建 If else 语句
- postgresql - Amazon RDS for PostgreSQL - 专用网络中的 POWER BI 连接失败
- amazon-web-services - 如何找出重复的 AWS CloudWatch 警报
- go - 自定义 golang sql.NullString Stringer 接口
- c# - 如何在 Unity3D Android 中创建日志文件?
- reactjs - 无法在 localhost 上打开 ReactJS 网站。从 Github 下载
- apache - 重定向 410 网址格式
- javascript - 猫鼬模式 [对象] 问题