【发布时间】:2020-09-05 23:16:59
【问题描述】:
编辑:已解决。
我不确定问题出在哪里,但我猜是关于 Rstudio。 当我将应用程序上传到 https://shinyapps.io/ 时,它可以工作了!
我正在尝试使用 shinyapp 渲染一个有情节的对象,
我在网上阅读了很多查询,其中大部分是关于使用“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)
【问题讨论】: