Skip to content

Commit bf58ee2

Browse files
committed
Refactor accordion panel creation in app-express.py
Replaces the previous list-based accordion panel creation with context-managed blocks for improved readability and structure. Updates dynamic panel insertion to match the new format, specifying both the section title and narrative.
1 parent 86e1252 commit bf58ee2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22

3-
from shiny import reactive, ui
4-
from shiny.express import input
3+
from shiny import reactive
4+
from shiny.express import input, ui
55

66

77
def make_panel(letter):
@@ -11,10 +11,18 @@ def make_panel(letter):
1111

1212

1313
ui.input_action_button("add_panel", "Add random panel", class_="mt-3 mb-3")
14-
ui.accordion(*[make_panel(letter) for letter in "ABCDE"], id="acc", multiple=True)
14+
15+
with ui.accordion(id="acc", multiple=True):
16+
for letter in "ABCDE":
17+
with ui.accordion_panel(f"Section {letter}"):
18+
f"Some narrative for section {letter}"
1519

1620

1721
@reactive.effect
1822
@reactive.event(input.add_panel)
1923
def _():
20-
ui.insert_accordion_panel("acc", make_panel(str(random.randint(0, 10000))))
24+
ui.insert_accordion_panel(
25+
"acc",
26+
f"Section {random.randint(0, 10000)}",
27+
f"Some narrative for section {random.randint(0, 10000)}",
28+
)

0 commit comments

Comments
 (0)