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
-
ui.accordion
ui.accordion(*args, id=None, open=None, multiple=True, class_=None, width=None, height=None, **kwargs)
-
ui.accordion_panel
ui.accordion_panel(title, *args, value=MISSING, icon=None, **kwargs)
-
ui.navset_card_tab
ui.navset_card_tab(*args, id=None, selected=None, title=None, sidebar=None, header=None, footer=None)
-
ui.navset_card_pill
ui.navset_card_pill(*args, id=None, selected=None, title=None, sidebar=None, header=None, footer=None, placement='above')
-
ui.navset_pill
ui.navset_pill(*args, id=None, selected=None, header=None, footer=None)
-
ui.navset_pill_list
ui.navset_pill_list(*args, id=None, selected=None, header=None, footer=None, well=True, widths=(4, 8))
-
ui.navset_tab
ui.navset_tab(*args, id=None, selected=None, header=None, footer=None)
Card with a tabbed tabset
#| standalone: true
#| components: [viewer]
#| layout: horizontal
#| viewerHeight: 250
## file: app.py
from shiny import App, ui
app_ui = ui.page_fillable(
ui.navset_card_tab(
ui.nav_panel("A", "Panel A content"),
ui.nav_panel("B", "Panel B content"),
ui.nav_panel("C", "Panel C content"),
ui.nav_menu(
"Other links",
ui.nav_panel("D", "Panel D content"),
"----",
"Description:",
ui.nav_control(
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
),
),
id="tab",
)
)
def server(input, output, session):
pass
app = App(app_ui, server)
from shiny.express import ui
ui.page_opts(fillable=True)
with ui.navset_card_tab(id="tab"):
with ui.nav_panel("A"):
"Panel A content"
with ui.nav_panel("B"):
"Panel B content"
with ui.nav_panel("C"):
"Panel C content"
with ui.nav_menu("Other links"):
with ui.nav_panel("D"):
"Page D content"
"----"
"Description:"
with ui.nav_control():
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
from shiny import App, ui
app_ui = ui.page_fillable(
ui.navset_card_tab(
ui.nav_panel("A", "Panel A content"),
ui.nav_panel("B", "Panel B content"),
ui.nav_panel("C", "Panel C content"),
ui.nav_menu(
"Other links",
ui.nav_panel("D", "Panel D content"),
"----",
"Description:",
ui.nav_control(
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
),
),
id="tab",
)
)
def server(input, output, session):
pass
app = App(app_ui, server)
Follow these steps to add a card with a tabbed tabset to your app:
Add
ui.navset_card_tab()
inside any Shiny UI page method (e.g.,ui.page_fluid()
).ui.navset_card_tab()
creates a tabset inside a card.Pass nav items (e.g.,
ui.nav_panel()
andui.nav_menu()
) toui.navset_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
title
argument ofui.nav_panel()
to control the displayed title of the nav item. Pass UI elements as additional arguments toui.nav_panel()
. These elements will be displayed when the tab is active.Optional: Pass a string to the
id
argument ofui.navset_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.py
from shiny import App, ui
app_ui = ui.page_fillable(
ui.navset_card_pill(
ui.nav_panel("A", "Panel A content"),
ui.nav_panel("B", "Panel B content"),
ui.nav_panel("C", "Panel C content"),
ui.nav_menu(
"Other links",
ui.nav_panel("D", "Panel D content"),
"----",
"Description:",
ui.nav_control(
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
),
),
id="tab",
)
)
def server(input, output, session):
pass
app = App(app_ui, server)
from shiny.express import ui
ui.page_opts(fillable=True)
with ui.navset_card_pill(id="tab"):
with ui.nav_panel("A"):
"Panel A content"
with ui.nav_panel("B"):
"Panel B content"
with ui.nav_panel("C"):
"Panel C content"
with ui.nav_menu("Other links"):
with ui.nav_panel("D"):
"Page D content"
"----"
"Description:"
with ui.nav_control():
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
from shiny import App, ui
app_ui = ui.page_fillable(
ui.navset_card_pill(
ui.nav_panel("A", "Panel A content"),
ui.nav_panel("B", "Panel B content"),
ui.nav_panel("C", "Panel C content"),
ui.nav_menu(
"Other links",
ui.nav_panel("D", "Panel D content"),
"----",
"Description:",
ui.nav_control(
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
),
),
id="tab",
)
)
def server(input, output, session):
pass
app = App(app_ui, server)
Follow these steps to add a card with a pill tabset to your app:
Add
ui.navset_card_pill()
inside any Shiny UI page method (e.g.,ui.page_fluid()
).ui.navset_card_pill()
creates a pillset inside a card.Pass nav items (e.g.,
ui.nav_panel()
andui.nav_menu()
) toui.navset_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
title
argument ofui.nav_panel()
to control the displayed title of the nav item. Pass UI elements as additional arguments toui.nav_panel()
. These elements will be displayed when the tab is active.Optional: Pass a string to the
id
argument ofui.navset_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.py
from shiny import App, ui
app_ui = ui.page_fluid(
ui.accordion(
ui.accordion_panel("Section A", "Section A content"),
ui.accordion_panel("Section B", "Section B content"),
ui.accordion_panel("Section C", "Section C content"),
ui.accordion_panel("Section D", "Section D content"),
ui.accordion_panel("Section E", "Section E content"),
id="acc",
open="Section A",
),
)
def server(input, output, session):
pass
app = App(app_ui, server)
from shiny.express import ui
with ui.accordion(id="acc", open="Section A"):
with ui.accordion_panel("Section A"):
"Section A content"
with ui.accordion_panel("Section B"):
"Section B content"
with ui.accordion_panel("Section C"):
"Section C content"
with ui.accordion_panel("Section D"):
"Section D content"
with ui.accordion_panel("Section E"):
"Section E content"
from shiny import App, ui
app_ui = ui.page_fluid(
ui.accordion(
ui.accordion_panel("Section A", "Section A content"),
ui.accordion_panel("Section B", "Section B content"),
ui.accordion_panel("Section C", "Section C content"),
ui.accordion_panel("Section D", "Section D content"),
ui.accordion_panel("Section E", "Section E content"),
id="acc",
open="Section A",
),
)
def server(input, output, session):
pass
app = App(app_ui, server)
Follow these steps to add vertically collapsing accordion panels to your app:
Add
ui.accordion()
inside any Shiny UI page method (e.g.,ui.page_fluid()
).ui.accordion()
creates a vertically collapsing accordion.Pass accordion panel items to
ui.accordion()
using calls toui.accordion_panel()
. Each call toui.accordion_panel()
creates one accordion panel.Pass arguments to the accordion panels to control each panel’s title, appearance, and associated content. The
*args
argument ofui.accordion_panel()
controls the contents of the accordion panel.Optional: Pass a string to the
id
argument ofui.accordian()
. 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()
.