r - 条件面板和选择输入

标签 r shiny plotly

这是我的问题;我无法正确设置 conditionalPanel 来与 selectInput 一起使用。我需要的是在选择“AP LIGUA”时绘制apligua,在选择“LAS CRUZADAS”时绘制lascruzadas。但 Shiny 正在绘制这两个图表。

请帮忙...

在服务器中:

vars <- data.frame(location = c("AP LIGUA",
                              "LAS CRUZADAS"),
                 lat = c(-32.45,
                         -32.183333),
                 lon = c(-71.216667,
                         -70.802222)
)

output$apligua <- renderPlotly({
 theme_set(theme_bw()) 
 ggplot(aes(x = datos2$horafecha, y = datos2$altura2), data = datos2) + 
   geom_line() +
   geom_point() +
   geom_smooth(method = "auto", colour='blue', span=0.2) +
   ylab("Altura (m) ") + 
   xlab("Meses")
})

output$lascruzadas <- renderPlotly({
 theme_set(theme_bw()) 
 ggplot(aes(x = datos$horafecha, y = datos$altura2), data = datos) + 
   geom_line() +
   geom_point() +
   geom_smooth(method = "auto", colour='blue', span=0.2) +
   ylab("Altura (m) ") + 
   xlab("Meses")
})

在用户界面中

selectInput(inputId = "myLocations", label = "Estación",
                                              choices = vars$location),

conditionalPanel("input.myLocations" == "LAS CRUZADAS",
                                plotlyOutput("lascruzadas", height = "100%")
                                ),

conditionalPanel("input.myLocations" == "AP LIGUA",
                                plotlyOutput("apligua", height ="100%")
                                )

(已编辑错误)

最佳答案

你的条件应该是Javascript代码的一个字符串。所以,类似于:

"input.myLocations == 'LAS CRUZADAS'"

注意单引号。

关于r - 条件面板和选择输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41961926/

相关文章:

r - "mean"表示值大于 x 的连续行(按组)

在 R Shiny 应用程序中重用输入

R Shiny 错误 : object of type 'closure' is not subsettable

python - 在 2 个不同的 plotly 数据帧直方图上共享相同的 x 轴

python - 如何提高 Plotly 的性能和响应时间

r - 从全名中分离姓氏

r - 为什么不同的机器学习方法在插入符号中给出相同的变量重要性?

r - dplyr 0.7.5 select() 行为的变化

html - 从 R Shiny App 输出纯 HTML 文件

R图表转换为html格式,无需其他文件