【问题标题】:R Shiny: conditionalPanel not working if used in different tabsR Shiny:如果在不同的选项卡中使用,conditionalPanel 不起作用
【发布时间】:2020-05-11 14:41:22
【问题描述】:

我的界面中需要多个选项卡,并且我想在每个选项卡中使用条件面板。正如您将在下面的可重现代码中看到的那样,conditionalPanel 在第一个选项卡中有效,但在其他选项卡中无效。

ui <- pageWithSidebar(
headerPanel("Hello !"),
sidebarPanel(
tabsetPanel(
tabPanel("a", 
textInput(inputId = "A1", label = "1:", value = "A1"),             
checkboxInput(inputId = "new_A2",
label = "Add another one",
value = FALSE),

conditionalPanel(
condition = "input.new_A2 == true",
textInput(inputId = "A2", label = "2:", value = "A2")
)),
tabPanel("b", 
textInput(inputId = "B1", label = "1:", value = "C1"),
checkboxInput(inputId = "new_B2",
label = "Add another one",
value = FALSE),

conditionalPanel(
condition = "input.new_B2 == true",

textInput(inputId = "B2", label = "2:", value = "C2")     
)
)
)
),

mainPanel()
)

server <- function(input,output){  
}

runApp(list(ui=ui,server=server))

我知道有很多关于条件面板的问题,但我还没有找到这个问题的答案。

提前谢谢你,任何建议都非常感谢

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    为您的标签集面板提供一个 ID,例如 tabsetPanel(id="tabs",并在标签“b”聚焦时添加条件 input.tabs == 'b'

    例如,在您的第二个条件面板中,条件将是:

    condition = "input.tabs == 'b' &amp; input.new_B2 == true"

    【讨论】:

    • 它不适用于闪亮版本 0.12.2.9007。如何检查属于输入的项目?比如闪亮的input$tabs?谢谢。
    • 好像是新版本的。 input.tabs == 'b' &amp; 应该删掉,就是原来的作品。
    【解决方案2】:

    使用条件面板,为了检查复选框输入的条件表达式,我们应该使用 1 而不是 TRUE。

    参考:Shiny App checkboxInput and conditionalPanel

    【讨论】:

    • 欢迎来到 SO。这似乎更像是评论而不是答案;请查看How to Answer 以获得指导。例如,某些上下文可能会有所帮助: checkboxInput {shiny} 的文档指出:“值:初始值(TRUE 或 FALSE)。”想必函数也可以取1或者0。还是说TRUE或者FALSE都不行?你调查过这个吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2017-04-21
    • 2020-04-11
    • 1970-01-01
    • 2021-10-15
    • 1970-01-01
    相关资源
    最近更新 更多