r - Shiny SidebarPanel selectInput 仅在选中复选框后
问题描述
我试图有一个闪亮的侧边栏面板,其中一个输入始终存在,一个仅在选中复选框后出现。我能找到的所有相关解决方案都在谈论在checkboxInput
上使用 for 条件output
,但我不确定如何实现这一点。为了显示我需要什么,这是我的代码片段:
require(shiny)
ui <- fluidPage(
titlePanel('My App'),
sidebarPanel(selectInput(inputId = "id1",
label = "something 1",
choices = c('a', 'b', 'c')),
checkboxInput("test_check", "Do you want to this?", value = FALSE),
uiOutput("test"), # checkbox to see if the user wants a comparison
selectInput(inputId = "id2",
label = "something2",
choices = c('a', 'b', 'c'))
),
mainPanel(
tabPanel("Some Info", htmlOutput(outputId = "info1"))
))
server <- function(input, output, session){}
shinyApp(ui = ui, server = server)
所以我希望id2
只有在选中复选框时才出现在侧边栏中,但不知道该怎么做。谢谢。
编辑:添加了一个最小的可重现示例。
解决方案
您可以将一些 UI 移动到服务器以检查该框,这是当一个输入依赖于另一个输入时我所做的,那么您只需要使用 req()
ui <- fluidPage(
titlePanel('My App'),
sidebarPanel(selectInput(inputId = "id1",
label = "something 1",
choices = c('a', 'b', 'c')),
checkboxInput("test_check", "Do you want to this?", value = FALSE),
uiOutput("test"), # checkbox to see if the user wants a comparison
uiOutput("id2")
),
mainPanel(
tabPanel("Some Info", htmlOutput(outputId = "info1"))
))
server <- function(input, output, session){
output$id2 <-
renderUI({
req(input$test_check)
selectInput(inputId = "id2",
label = "something2",
choices = c('a', 'b', 'c'))
})
}
shinyApp(ui = ui, server = server)
推荐阅读
- linux - SECTION .DATA 中存在变量的分段错误
- php - 循环遍历 html 表并使用简单的 dom 解析器在 php 中获取 tr、th 和 td
- c# - 如何在 Asp.net C# 的另一个页面上显示 ViewDetail
- java - Java + spring - 在无限循环中以随机间隔运行动作
- java - apache Storm - 在单节点中正确运行 jar,但在多节点中不正确
- maven - 从 maven 构建 jar 后无法运行 spark-submit
- python - 使 matplotlib 图部分不可见
- r - 芝加哥犯罪数据集的线性回归可能吗?
- javascript - 在 Heroku 上使用 JavaScript 模块
- cmake - CMake 在单个构建中针对多个平台