闪亮的无功输入值 - 没有图表,没有错误

时间:2016-09-08 09:55:19

标签: r shiny

几个星期前,我已经询问过R-Shiny的反应性,我仍然没有设法破解坚果。它让我疯狂,我已经阅读了100篇关于反应性的文章,但我无法让它发挥作用!

这是我到目前为止所得到的:

ui.R:

column(width = 3,
box(
   title = "Pick a metric",
       status = "primary",
       width = 12,
       height = 200,
       solidHeader = FALSE,
       collapsible = FALSE,
       selectInput("value", "Metric:",
                   c("Pages / Session" = "pageviewsPerSession",
                        "Avg. Session Duration" = "avgSessionDuration"))
                                   )  )
  column(width = 9,
                              box(
                                title = "Title",
                                status = "primary",
                                width = 12,
                                height = 950,
                                solidHeader = FALSE,
                                collapsible = FALSE,
                                          plotlyOutput("Scatter1")

server.R:

output$Scatter1 <- renderPlotly({ 

datasetInput <- reactive({
  switch(input$value,
     "Pages / Session" =  SourcesDetail$pageviewsPerSession,
     "Avg. Session Duration" = SourcesDetail$avgSessionDuration)
})

p <- plot_ly(SourcesDetail, x = datasetInput(), y = SourcesDetail$visits, text = paste("Source/Medium: ", SourcesDetail$sourceMedium),
         mode = "markers", color = SourcesDetail$medium, opacity = SourcesDetail$sourceMedium, marker = list(size = 15))

})

没有错误信息,输出中根本没有图表。

任何帮助都将不胜感激!!

1 个答案:

答案 0 :(得分:0)

您将输出分配给p但不输出p本身。删除p <-或在p末尾添加一个renderPlotly

无论

output$Scatter1 <- renderPlotly({ 

  datasetInput <- reactive({
    switch(input$value,
           "Pages / Session" =  SourcesDetail$pageviewsPerSession,
           "Avg. Session Duration" = SourcesDetail$avgSessionDuration)
  })

  plot_ly(SourcesDetail, x = datasetInput(), y = SourcesDetail$visits, text = paste("Source/Medium: ", SourcesDetail$sourceMedium),
               mode = "markers", color = SourcesDetail$medium, opacity = SourcesDetail$sourceMedium, marker = list(size = 15))

})

output$Scatter1 <- renderPlotly({ 

  datasetInput <- reactive({
    switch(input$value,
           "Pages / Session" =  SourcesDetail$pageviewsPerSession,
           "Avg. Session Duration" = SourcesDetail$avgSessionDuration)
  })

  p <- plot_ly(SourcesDetail, x = datasetInput(), y = SourcesDetail$visits, text = paste("Source/Medium: ", SourcesDetail$sourceMedium),
               mode = "markers", color = SourcesDetail$medium, opacity = SourcesDetail$sourceMedium, marker = list(size = 15))
  p
})