1
votes

Is there a way to select the default tab on start up using bs4Dash R package?

With shinydashboard I used updateTabSetPanel to set the default tab at the start.

Below is reproducible example, I would like the tab named "start" to be the one selected on start.

library(shiny)
library(bs4Dash)

shiny::shinyApp(
  ui = bs4DashPage(
    navbar = bs4DashNavbar(),
    sidebar = bs4DashSidebar(
      skin = "light",
      bs4SidebarMenu(
        bs4SidebarHeader("Main content"),
        bs4SidebarMenuItem(
          "Classic theme",
          tabName = "classic",
          icon = "desktop"
        ),
        bs4SidebarMenuItem(
          "Start with me",
          tabName = "start", # <---- start with me!
          icon = "map"
        )
      )
    ),
    controlbar = bs4DashControlbar(
      skin = "light"
    ),
    footer = bs4DashFooter(),
    title = "Classic theme",
    body = bs4DashBody(
      bs4TabItems(
        bs4TabItem(
          tabName = "classic",
          fluidRow(
            bs4Box(
              height = "600px",
              title = "Box 1"
            ),
            bs4Box(
              height = "600px",
              title = "Box 2"
            )
          )
        )
      )
    )
  ),
  server = function(input, output) {}
)
1
Reading this github.com/RinteRface/bs4Dash/issues/8 I dont know if it is feasible...LocoGris

1 Answers

3
votes

Use JavaScript to select the tab manually, after the Shiny session has initialized:

tags$head(tags$script('
  $(document).on("shiny:sessioninitialized", function(event) {
    $(\'a[data-value="start"]\').tab("show");
  });
')),

You can include this snippet in bs4DashBody.