express.ui.insert_accordion_panel

express.ui.insert_accordion_panel(
    id,
    panel_title,
    *panel_contents,
    panel_value=MISSING,
    panel_icon=None,
    target=None,
    position='after',
    session=None,
)

Insert an accordion panel into an existing accordion.

Parameters

id : str

A string that matches an existing accordion’s id.

panel_title : str

The title to appear in the panel header.

panel_contents : Union[TagChild, TagAttrs] = ()

UI elements for the panel’s body. Can also be a dict of tag attributes for the body’s HTML container.

panel_value : Union[str, MISSING_TYPE, None] = MISSING

A character string that uniquely identifies this panel. If MISSING, the title will be used.

panel_icon : TagChild = None

A TagChild which is positioned just before the title.

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

  • accordion
  • accordion_panel
  • update_accordion

Examples

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

## file: app.py
import random

from shiny import reactive
from shiny.express import input, ui

ui.input_action_button("add_panel", "Add random panel", class_="mt-3 mb-3")

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


@reactive.effect
@reactive.event(input.add_panel)
def _():
    ui.insert_accordion_panel(
        "acc",
        f"Section {random.randint(0, 10000)}",
        f"Some narrative for section {random.randint(0, 10000)}",
    )