express.ui.insert_accordion_panel

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

Insert an accordion_panel.

Parameters

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

References

Bootstrap Accordion

See Also

Examples

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

## file: app.py
import random

from shiny import reactive, ui
from shiny.express 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)


@reactive.effect
@reactive.event(input.add_panel)
def _():
    ui.insert_accordion_panel("acc", make_panel(str(random.randint(0, 10000))))