几个星期前,我已经询问过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))
})
没有错误信息,输出中根本没有图表。
任何帮助都将不胜感激!!
答案 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
})