I am using a shiny::conditionalPanel
inside a shinyBS::bsCollapsePanel
. I have logic in my app that depends on which shinyBS panel is active (i.e., expanded). This works fine until I activate the conditional panel. If I show the Shiny conditional panel, then the shinyBS collapse panel gets stuck as active even when the panel is inactive (i.e., closed).
How can I modify my code so that the collapsible panels only register as active if they are expanded?
In this example there is a text output indicating the active panel. Switching between panels works correctly unless the conditional panels are shown.
EDIT: It appears this bug may already be documented (https://github.com/ebailey78/shinyBS/issues/38) and there is a possible solution (https://github.com/ebailey78/shinyBS/pull/68/commits).
library(shiny)
library(shinyBS)
# Define UI logic
ui <- fluidPage(
htmlOutput("activePanel"),
shinyBS::bsCollapse(
id = "bsPanels",
shinyBS::bsCollapsePanel(
"Panel A",
value = "panelA",
checkboxInput("showPanelA",
"Show panel",
value = FALSE),
conditionalPanel(
condition = "input.showPanelA",
helpText("Panel A conditional content")
),
helpText("Panel A main content")
),
shinyBS::bsCollapsePanel(
"Panel B",
value = "panelB",
checkboxInput("showPanelB",
"Show panel",
value = FALSE),
conditionalPanel(
condition = "input.showPanelB",
helpText("Panel B conditional content")
),
helpText("Panel B main content")
)
)
)
# Define server logic
server <- function(input, output) {
output$activePanel <- renderText({
paste("<b>Active Panel:</b>", paste(input$bsPanels, collapse = ", "))
})
}
# Run the application
shinyApp(ui = ui, server = server)
updateCheckboxInput()
in anobserveEvent()
where the checkbox gets unticked when the panels change...didn't work with the bug though, glad you've found a possible solution! – Jaccar