ui.insert_accordion_panel
ui.insert_accordion_panel(id,
panel,=None,
target='after',
position=None,
session )
Insert an accordion_panel
.
Parameters
id : str
-
A string that matches an existing
accordion
’sid
. 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? Whentarget=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
See Also
Examples
#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
## file: app.py
import random
from shiny import App, Inputs, Outputs, Session, reactive, ui
def make_panel(letter: str) -> ui.AccordionPanel:
return ui.accordion_panel(
f"Section {letter}", f"Some narrative for section {letter}"
)
items = [make_panel(letter) for letter in "ABCDE"]
app_ui = ui.page_fluid(
ui.input_action_button("add_panel", "Add random panel", class_="mt-3 mb-3"),
ui.accordion(*items, id="acc", multiple=True),
)
def server(input: Inputs, output: Outputs, session: Session):
@reactive.effect
@reactive.event(input.add_panel)
def _():
ui.insert_accordion_panel("acc", make_panel(str(random.randint(0, 10000))))
app = App(app_ui, server)