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

Dynamically set accordions' states.

Dynamically (i.e., programmatically) update/modify accordions in a Shiny app. These functions require an id to be provided to the accordion and must also be called within an active Shiny session.


id: str

A string that matches an existing accordion’s id.

show: bool | str | list[str]

Either a string or list of strings (used to identify particular accordion_panel(s) by their value) or a bool to set the state of all panels.

session: Optional[Session] = None

A Shiny session object (the default should almost always be used).


Bootstrap Accordion

See Also


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

## file:
from shiny import reactive
from import input, ui

ui.input_action_button("set_acc", "Only open sections A,C,E", class_="mt-3 mb-3")

with ui.accordion(id="acc", open=["Section B", "Section D"], multiple=True):
    for letter in "ABCDE":
        with ui.accordion_panel(f"Section {letter}"):
            f"Some narrative for section {letter}"

def _():
    ui.update_accordion("acc", show=["Section A", "Section C", "Section E"])