r - 根据闪亮应用程序中的参数1值隐藏/显示参数2
问题描述
我是闪亮的应用程序/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”。
解决方案
您可以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
才能使其正常工作。
推荐阅读
- python - 对象之间通配符匹配的简洁方法?
- mysql - 此代码显示用户列表 bt 如何将其转换为 Nodejs 和 mysql 中的 MVC 模型?
- angularjs - 根据条件angularjs显示视图输入字段
- android - RadioButton 状态和按钮验证
- c# - Office365 - 使用 C# 列出用户
- python-3.x - 使用二维嵌套字典中的 if/else 语句进行列表理解循环
- node.js - nodejs到mosquitto raspberry pi pub sub不起作用
- java - PostgreSQL - 找不到适用于 JDBC 的驱动程序
- javascript - AJAX - JSON 未定义(jQuery、NodeJS)
- angular - 使用插值设置 routerLink