conditionalPanel和selectInput

时间:2017-01-31 15:58:58

标签: 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%")
                                )

(已编辑错误)

1 个答案:

答案 0 :(得分:2)

您的条件应该是Javascript代码的一个字符串。所以,像:

"input.myLocations == 'LAS CRUZADAS'"

请注意单引号。