Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny: conditionalPanel not working if used in different tabs

Tags:

r

shiny

I would need multiple tabs in my interface, and in each of them I would like to use conditionalPanel. As you will see with the reproducible code here below, the conditionalPanel works in the first tab, but not in the 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 there are many questions related to conditionalPanel, but I haven't found the answer to this one yet.

Thank you in advance, any suggestion highly appreciated

like image 879
user1431694 Avatar asked Feb 14 '23 17:02

user1431694


1 Answers

Give your tabset panel an id for example tabsetPanel(id="tabs" and add the condition when the tab "b" is focused input.tabs == 'b'

For example in your 2nd conditional panel the condition will be :

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

like image 99
Julien Navarre Avatar answered Feb 17 '23 16:02

Julien Navarre