express.ui.update_accordion

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.

Parameters

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).

References

Bootstrap Accordion

See Also

Examples

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

## file: app.py
from shiny import reactive
from shiny.express 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}"


@reactive.effect
@reactive.event(input.set_acc)
def _():
    ui.update_accordion("acc", show=["Section A", "Section C", "Section E"])