express.ui.toggle_offcanvas

express.ui.toggle_offcanvas(id, show=None, *, session=None)

Toggle an offcanvas panel's visibility.

Parameters

id : str

The ID of the offcanvas panel.

show : Optional[bool] = None

If None (default), toggle the current state. If True, show the panel. If False, hide the panel.

session : Optional[Session] = None

The Session to use. If not provided, the session is inferred via get_current_session.

See Also

Examples

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

## file: app.py
from shiny import reactive
from shiny.express import input, render, ui

panel = ui.offcanvas(
    ui.p("This is the offcanvas body content."),
    title="Offcanvas Panel",
    id="panel",
)

panel
ui.input_action_button("toggle_btn", "Toggle panel")
ui.input_action_button("hide_btn", "Hide panel")


@render.text
def state():
    return f"Panel is {'open' if input.panel() else 'closed'}"


@reactive.effect
@reactive.event(input.toggle_btn)
def _():
    ui.toggle_offcanvas("panel")


@reactive.effect
@reactive.event(input.hide_btn)
def _():
    ui.hide_offcanvas("panel")