Skip to content

showTab not displaying contents properly with bslib #1261

@philstraforelli

Description

@philstraforelli

Describe the problem

I'm running into an issue where bslib is not displaying the contents of a tab with showTab() when "base" shiny is working fine.

Here's an example of a "base" shiny that works as desired:

library(shiny)
library(bslib)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      checkboxGroupInput("create_tabs", label = "Select an option to create a tab",
                         choices = c("Letters", "Numbers", "Symbols")),
      tabsetPanel(id = "Options",
                  tabPanel("Letters", checkboxGroupInput("Letter_options", label = "Letter options",
                                                         choices = LETTERS[1:5])),
                  tabPanel("Numbers", checkboxGroupInput("Number_options", label = "Number options",
                                                         choices = 1:5)),
                  tabPanel("Symbols", checkboxGroupInput("Symbol_options", label = "Symbol options",
                                                         choices = c("$", "#", "&", "!", "?")))
      )
    ),
    mainPanel()
  )
)

server <- function(input, output, session) {
  observe({
    if ("Letters" %in% input$create_tabs) {
      showTab("Options", target = "Letters", select = TRUE)
    } else {
      hideTab("Options", target = "Letters")  
    }
    
    if ("Numbers" %in% input$create_tabs) {
      showTab("Options", target = "Numbers", select = TRUE)
    } else {
      hideTab("Options", target = "Numbers")  
    }
    
    if ("Symbols" %in% input$create_tabs) {
      showTab("Options", target = "Symbols", select = TRUE)
    } else {
      hideTab("Options", target = "Symbols")  
    }
  })
}

shinyApp(ui, server)

See this gif of the app working as desired: https://i.imgur.com/qJMMtwb.mp4

However, if I implement bslib using the following code:

ui <- page_sidebar(
  sidebar = sidebar(
    checkboxGroupInput("create_tabs", label = "Select an option to create a tab",
                       choices = c("Letters", "Numbers", "Symbols")),
    tabsetPanel(id = "Options",
                tabPanel("Letters", checkboxGroupInput("Letter_options", label = "Letter options",
                                                       choices = LETTERS[1:5])),
                tabPanel("Numbers", checkboxGroupInput("Number_options", label = "Number options",
                                                       choices = 1:5)),
                tabPanel("Symbols", checkboxGroupInput("Symbol_options", label = "Symbol options",
                                                       choices = c("$", "#", "&", "!", "?")))
    )
  ),
  card()
)

Now when I select a tab to open, the contents do not show: https://i.imgur.com/R74cENE.gif

Session Info


version  R version 4.5.2 (2025-10-31 ucrt)
 os       Windows 11 x64 (build 26200)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
package     * version    date (UTC) lib source
 bslib       * 0.9.0.9002 2025-11-21 [1] Github (rstudio/bslib@0757592)
shiny       * 1.11.1     2025-07-03 [1] CRAN (R 4.5.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions