SelectInput和if loop plot R Shiny

时间:2017-01-31 08:00:10

标签: r shiny plotly

我知道这是一个基本问题,但我在Shiny中真的很新......

如何将plotlyOutput与SelectInput框中的if循环结合使用?

我的意思是这样的:

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

selectInput(inputId = "myLocations", label = "Estación",
                                              choices = vars$location),
if (vars$location=="AP LIGUA") {
                                plotlyOutput("apligua", height = "100%")
                                fluidRow(
                                  DT::dataTableOutput("table")
                                )
                              }

但它不起作用。

1 个答案:

答案 0 :(得分:1)

我想你截断了你的代码?它看起来不像一个闪亮的应用程序。这是一个闪亮的应用程序应该是什么样子。

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

ui <- fluidPage(
  selectInput(inputId = "myLocations", label = "Estación",
                                              choices = vars$location),
  plotlyOutput("apligua", height = "100%"),
  dataTableOutput("table")
)

server <- function(input, output,session) {

  output$apligua <- renderPlotly({
    if(is.null(input$myLocations)) return() #react to the user's choice if there's one

    plot_ly(...)
  })

  output$table <- renderDataTable({
    if(is.null(input$myLocations)) return() #same thing, react to the user's choice

    data.table(...)
  })
}

shinyApp(ui, server)