express.ui.insert_accordion_panel(id, panel, target=None, position='after', session=None)

Insert an accordion_panel.


id: str

A string that matches an existing accordion’s id.

panel: AccordionPanel

An accordion_panel object to insert.

target: Optional[str] = None

The value of an existing panel to insert next to.

position: Literal[‘after’, ‘before’] = ‘after’

Should panel be added before or after the target? When target=None, "after" will append after the last panel and "before" will prepend before the first panel.

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:
import random

from shiny import reactive, ui
from import input

def make_panel(letter):
    return ui.accordion_panel(
        f"Section {letter}", f"Some narrative for section {letter}"

ui.input_action_button("add_panel", "Add random panel", class_="mt-3 mb-3")
ui.accordion(*[make_panel(letter) for letter in "ABCDE"], id="acc", multiple=True)

def _():
    ui.insert_accordion_panel("acc", make_panel(str(random.randint(0, 10000))))