Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

updateTabItems

Change the selected tab on the client


Description

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

Usage

updateTabItems(session, inputId, selected = NULL)

Arguments

session

The session object passed to function given to shinyServer.

inputId

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

selected

The name of the tab to make active.

Examples

## 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)
}

shinydashboard

Create Dashboards with 'Shiny'

v0.7.1
GPL (>= 2) | file LICENSE
Authors
Winston Chang [aut, cre], Barbara Borges Ribeiro [aut], RStudio [cph], Almasaeed Studio [ctb, cph] (AdminLTE theme for Bootstrap), Adobe Systems Incorporated [ctb, cph] (Source Sans Pro font)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.