我是闪亮的Apps / R的新手,需要您的帮助才能解决以下情况。
ui <- fluidPage(
selectInput(inputId = "para1",label = "parameter1", choices = c("var1","Var2")),
selectInput(inputId = "para2",label = "parameter2", choices = c("cars","trucks"))
)
server <- function(input,output,session){
output$text <- renderText("control parameters")
}
shinyApp(ui,server)
我的要求是在选择“ parameter1”值的基础上显示/隐藏“ parameter2”。
假设我选择parameter1=="var1"
,然后显示“ parameter2”,否则隐藏整个“ parameter2”。
答案 0 :(得分:1)
您可以将shinyjs::toggle
与uiOutput
结合使用:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
selectInput(inputId = "para1",label = "parameter1", choices = c("var1","var2")),
uiOutput("selectPara2")
)
server <- function(input,output,session){
output$selectPara2 <- renderUI(selectInput(inputId = "para2",label = "parameter2", choices = c("cars","trucks")))
shiny::observeEvent(input$para1, {
shinyjs::toggle("selectPara2", condition = input$para1 == "var1")
})
}
shinyApp(ui,server)
请注意,useShinyjs()
必须在UI
中调用才能起作用。