繁体   English   中英

SelectInput和if循环图R Shiny

[英]SelectInput and if loop plot R Shiny

我知道这是一个基本问题,但是我在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")
                                )
                              }

但这行不通。

我想您将代码截断了吗? 它看起来并不像一个闪亮的应用程序。 这就是闪亮的应用程序的外观。

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM