R Shiny: conditionalPanel does not work if used in different tabs

I would need several tabs in my interface, and in each of them I would like to use a conditionalPanel. As you will see here with reproducible code, the conditional panel works on the first tab, but not on other tabs.

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))

I know that there are many questions related to conditionalPanel, but I have not yet found the answer to this question.

Thanks in advance, any suggestion highly appreciated

+4
source share
1 answer

Give your tablet panel an identifier, for example tabsetPanel(id="tabs", and add a condition when the tab "b" is focusedinput.tabs == 'b'

For example, in your second conditional panel, the condition will be:

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

+6

Source: https://habr.com/ru/post/1527964/


All Articles