Learn R Programming

shinydashboard (version 0.7.3)

updateTabItems: Change the selected tab on the client

Description

This function controls the active tab of tabItems() from the server. It behaves just like shiny::updateTabsetPanel().

Usage

updateTabItems(...)

Arguments

...

Arguments passed on to shiny::updateTabsetPanel

session

The session object passed to function given to shinyServer. Default is getDefaultReactiveDomain().

inputId

The id of the tabsetPanel, navlistPanel, or navbarPage object.

selected

The value (or, if none was supplied, the title) of the tab that should be selected by default. If NULL, the first tab will be selected.

Examples

Run this code
## Only run this example in interactive R sessions
if (interactive()) {

ui <- dashboardPage(
  dashboardHeader(title = "Simple tabs"),
  dashboardSidebar(
    sidebarMenu(
      id = "tabs",
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", tabName = "widgets", icon = icon("th"))
    ),
    actionButton('switchtab', 'Switch tab')
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "dashboard",
        h2("Dashboard tab content")
      ),
      tabItem(tabName = "widgets",
        h2("Widgets tab content")
      )
    )
  )
)

server <- function(input, output, session) {
  observeEvent(input$switchtab, {
    newtab <- switch(input$tabs,
      "dashboard" = "widgets",
      "widgets" = "dashboard"
    )
    updateTabItems(session, "tabs", newtab)
  })
}

shinyApp(ui, server)
}

Run the code above in your browser using DataLab