Tabs
Tabs and navigation allow you to create Shiny apps with multiple pages.
Tabs and navigation allow you to create apps that have multiple pages.
Relevant Functions
-
navset_pill
navset_pill(..., id = NULL, selected = NULL, header = NULL, footer = NULL) -
navset_card_pill
navset_card_pill(..., id = NULL, selected = NULL, title = NULL, sidebar = NULL, header = NULL, footer = NULL, height = NULL, placement = c("above", "below"), full_screen = FALSE, wrapper = card_body) -
navset_pill_list
navset_pill_list(..., id = NULL, selected = NULL, header = NULL, footer = NULL, well = TRUE, fluid = TRUE, widths = c(4, 8)) -
navset_card_pill
navset_card_pill(..., id = NULL, selected = NULL, title = NULL, sidebar = NULL, header = NULL, footer = NULL, height = NULL, placement = c("above", "below"), full_screen = FALSE, wrapper = card_body) -
navset_tab
navset_tab(..., id = NULL, selected = NULL, header = NULL, footer = NULL) -
navset_card_tab
navset_card_tab(..., id = NULL, selected = NULL, title = NULL, sidebar = NULL, header = NULL, footer = NULL, height = NULL, full_screen = FALSE, wrapper = card_body)
Card with a tabbed tabset
#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 250
## file: app.R
library(shiny)
library(bslib)
ui <- page_fillable(
navset_card_tab(
nav_panel("A", "Page A content"),
nav_panel("B", "Page B content"),
nav_panel("C", "Page C content"),
nav_menu(
"Other links",
nav_panel("D", "Panel D content"),
"----",
"Description:",
nav_item(
a("Shiny", href = "https://shiny.posit.co", target = "_blank")
),
),
),
id = "tab"
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
ui <- page_fillable(
navset_card_tab(
nav_panel("A", "Page A content"),
nav_panel("B", "Page B content"),
nav_panel("C", "Page C content"),
nav_menu(
"Other links",
nav_panel("D", "Panel D content"),
"----",
"Description:",
nav_item(
a("Shiny", href = "https://shiny.posit.co", target = "_blank")
),
),
),
id = "tab"
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)Follow these steps to add a card with a tabbed tabset to your app:
Add
navset_card_tab()inside any Shiny UI page method (e.g.,page_fluid()).navset_card_tab()creates a tabset inside a card.Pass nav items (e.g.,
nav_panel()andnav_menu()) tonavset_card_tab()to set the items displayed in the tabset inside the card.Pass arguments to the nav items to control each item’s title, appearance, and associated content. For example, set the
titleargument ofnav_panel()to control the displayed title of the nav item. Pass UI elements as additional arguments tonav_panel(). These elements will be displayed when the tab is active.Optional: Pass a string to the
idargument ofnavset_card_tab(). This will create an input value that holds the title of the currently selected nav item. For example,id = "tab"would create a reactive value accessible asinput$tab.
Card with a pill tabset
#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 250
## file: app.R
library(shiny)
library(bslib)
ui <- page_fillable(
navset_card_pill(
nav_panel("A", "Page A content"),
nav_panel("B", "Page B content"),
nav_panel("C", "Page C content"),
nav_menu(
"Other links",
nav_panel("D", "Panel D content"),
"----",
"Description:",
nav_item(
a("Shiny", href = "https://shiny.posit.co", target = "_blank")
),
),
),
id = "tab"
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
ui <- page_fillable(
navset_card_pill(
nav_panel("A", "Page A content"),
nav_panel("B", "Page B content"),
nav_panel("C", "Page C content"),
nav_menu(
"Other links",
nav_panel("D", "Panel D content"),
"----",
"Description:",
nav_item(
a("Shiny", href = "https://shiny.posit.co", target = "_blank")
),
),
),
id = "tab"
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)Follow these steps to add a card with a pill tabset to your app:
Add
navset_card_pill()inside any Shiny UI page method (e.g.,page_fluid()).navset_card_pill()creates a pillset inside a card.Pass nav items (e.g.,
nav_panel()andnav_menu()) tonavset_card_pill()to set the items displayed in the pillset inside the card.Pass arguments to the nav items to control each item’s title, appearance, and associated content. For example, set the
titleargument ofnav_panel()to control the displayed title of the nav item. Pass UI elements as additional arguments tonav_panel(). These elements will be displayed when the tab is active.Optional: Pass a string to the
idargument ofnavset_card_pill(). This will create an input value that holds the title of the currently selected nav item. For example,id = "tab"would create a reactive value accessible asinput$tab.
Vertically collapsing accordion panels
#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 350
## file: app.R
library(shiny)
library(bslib)
ui <- page_fluid(
accordion(
accordion_panel(
title = "Section A",
icon = bsicons::bs_icon("menu-app"),
"Section A content"
),
accordion_panel(
title = "Section B",
icon = bsicons::bs_icon("sliders"),
"Section B content"
),
accordion_panel(
title = "Section C",
icon = bsicons::bs_icon("bar-chart"),
"Section C content"
),
accordion_panel(
title = "Section D",
icon = bsicons::bs_icon("calendar-date"),
"Section D content"
),
id = "acc",
open = "Section A"
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)
ui <- page_fluid(
accordion(
accordion_panel(
title = "Section A",
icon = bsicons::bs_icon("menu-app"),
"Section A content"
),
accordion_panel(
title = "Section B",
icon = bsicons::bs_icon("sliders"),
"Section B content"
),
accordion_panel(
title = "Section C",
icon = bsicons::bs_icon("bar-chart"),
"Section C content"
),
accordion_panel(
title = "Section D",
icon = bsicons::bs_icon("calendar-date"),
"Section D content"
),
id = "acc",
open = "Section A"
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
Follow these steps to add vertically collapsing accordion panels to your app:
Add
accordion()inside any Shiny UI page method (e.g.,page_fluid()).accordion()creates a vertically collapsing accordion.Pass accordion panel items to
accordion()using calls toaccordion_panel(). Each call toaccordion_panel()creates one accordion panel.Use
accordion_panel()’stitleargument to control a panel’s title. Optionally, set an icon for anaccordion_panel()using theiconargument. Pass UI elements as additional arguments toaccordion_panel(). These elements will be displayed when the panel is expanded.Optional: Pass a string to the
idargument ofaccordian(). This will create an input value that represents the currently active accordion panels. For example,id = "panel"would create a reactive value accessible asinput$panel.