ui.update_nav_panel

ui.update_nav_panel(id, target, method, session=None)

Show/hide a navigation item

Parameters

id : str

The id of the relevant navigation container (i.e., navset_*() object).

target : str

The value of an existing shiny.ui.nav_panel item to show.

method : Literal[‘show’, ‘hide’]

The action to perform on the nav_panel ("show" or "hide").

session : Optional[Session] = None

A Session instance. If not provided, it is inferred via get_current_session.

Note

On reveal, the nav_panel will not be the active tab. To change the active tab, use :func:~shiny.ui.update_navset() For example:

@reactive.effect
@reactive.event(input.show_tab)
def _():
    ui.update_nav_panel("tabset_id", target="Foo", method="show")
    ui.update_navset("tabset_id", selected="Foo")

See Also

insert_nav_panel remove_nav_panel nav_panel update_navset

Examples

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

## file: app.py
from shiny import App, Inputs, Outputs, Session, reactive, ui

app_ui = ui.page_sidebar(
    ui.sidebar(
        "Home",
        ui.input_action_button("hideTab", "Hide 'Foo' tab"),
        ui.input_action_button("showTab", "Show 'Foo' tab"),
        ui.input_action_button("hideMenu", "Hide 'More' nav_menu"),
        ui.input_action_button("showMenu", "Show 'More' nav_menu"),
    ),
    ui.navset_tab(
        ui.nav_panel("Foo", "This is the foo tab", value="Foo"),
        ui.nav_panel("Bar", "This is the bar tab", value="Bar"),
        ui.nav_menu(
            "More",
            ui.nav_panel("Table", "Table page"),
            ui.nav_panel("About", "About page"),
            "------",
            "Even more!",
            ui.nav_panel("Email", "Email page"),
            value="More",
        ),
        id="tabs",
    ),
    title="Navbar page",
    id="sidebar",
)


def server(input: Inputs, output: Outputs, session: Session):
    @reactive.effect
    @reactive.event(input.hideTab)
    def _():
        ui.update_nav_panel("tabs", target="Foo", method="hide")

    @reactive.effect
    @reactive.event(input.showTab)
    def _():
        ui.update_nav_panel("tabs", target="Foo", method="show")

    @reactive.effect
    @reactive.event(input.hideMenu)
    def _():
        ui.update_nav_panel("tabs", target="More", method="hide")

    @reactive.effect
    @reactive.event(input.showMenu)
    def _():
        ui.update_nav_panel("tabs", target="More", method="show")


app = App(app_ui, server)