ui.navset_bar

ui.navset_bar(*args, title, id=None, selected=None, sidebar=None, fillable=True, gap=None, padding=None, position='static-top', header=None, footer=None, bg=None, inverse=False, underline=True, collapsible=True, fluid=True)

Render nav items as a navbar.

Parameters

*args: NavSetArg | MetadataNode | Sequence[MetadataNode] = ()

A collection of nav items (e.g., shiny.ui.nav_panel).

title: TagChild

Title to display in the navbar.

id: Optional[str] = None

If provided, will create an input value that holds the currently selected nav item.

selected: Optional[str] = None

Choose a particular nav item to select by default value (should match it’s value).

sidebar: Optional[Sidebar] = None

A Sidebar component to display on every nav_panel page.

fillable: bool | list[str] = True

Whether or not to allow fill items to grow/shrink to fit the browser window. If True, all nav() pages are fillable. A character vector, matching the value of nav()s to be filled, may also be provided. Note that, if a sidebar is provided, fillable makes the main content portion fillable.

gap: Optional[CssUnit] = None

A CSS length unit defining the gap (i.e., spacing) between elements provided to *args.

padding: Optional[CssUnit | list[CssUnit]] = None

Padding to use for the body. This can be a numeric vector (which will be interpreted as pixels) or a character vector with valid CSS lengths. The length can be between one and four. If one, then that value will be used for all four sides. If two, then the first value will be used for the top and bottom, while the second value will be used for left and right. If three, then the first will be used for top, the second will be left and right, and the third will be bottom. If four, then the values will be interpreted as top, right, bottom, and left respectively.

position: Literal[‘static-top’, ‘fixed-top’, ‘fixed-bottom’, ‘sticky-top’] = ‘static-top’

Determines whether the navbar should be displayed at the top of the page with normal scrolling behavior (“static-top”), pinned at the top (“fixed-top”), or pinned at the bottom (“fixed-bottom”). Note that using “fixed-top” or “fixed-bottom” will cause the navbar to overlay your body content, unless you add padding (e.g., tags.style("body {padding-top: 70px;}")).

header: TagChild = None

UI to display above the selected content.

footer: TagChild = None

UI to display below the selected content.

bg: Optional[str] = None

Background color of the navbar (a CSS color).

inverse: bool = False

Either True for a light text color or False for a dark text color.

collapsible: bool = True

True to automatically collapse the navigation elements into an expandable menu on mobile devices or narrow window widths.

fluid: bool = True

True to use fluid layout; False to use fixed layout.

See Also

Example

See nav_panel.

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
from shiny import App, render, ui

app_ui = ui.page_fluid(
    ui.navset_bar(
        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="selected_navset_bar",
        title="Navset Bar",
    ),
    ui.h5("Selected:"),
    ui.output_code("selected"),
)


def server(input, output, session):
    @render.code
    def selected():
        return input.selected_navset_bar()


app = App(app_ui, server)