[英]SelectInput and if loop plot R Shiny
I know this is a basic question, but I'm really new at Shiny... 我知道这是一个基本问题,但是我在Shiny真的很新...
How can I combine plotlyOutput with an if loop from a SelectInput box? 如何将plotlyOutput与SelectInput框中的if循环结合?
I mean something like this: 我的意思是这样的:
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")
)
}
But it does not work. 但这行不通。
I suppose you truncated your code? 我想您将代码截断了吗? It doesn't look very much like a shiny app. 它看起来并不像一个闪亮的应用程序。 This is what a shiny app should look like. 这就是闪亮的应用程序的外观。
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.