|
1 | 1 | from shiny import reactive |
2 | 2 | from shiny.express import input, ui |
3 | 3 |
|
4 | | -with ui.layout_sidebar(): |
5 | | - with ui.sidebar(): |
6 | | - ui.input_action_button("add", "Add 'Dynamic' tab") |
7 | | - ui.input_action_button("removeFoo", "Remove 'Foo' tabs") |
8 | | - ui.input_action_button("addFoo", "Add New 'Foo' tab") |
9 | | - |
10 | | - with ui.navset_tab(id="set"): |
11 | | - with ui.nav_panel("Hello", value="Hello"): |
12 | | - "This is the hello tab" |
13 | | - with ui.nav_panel("Foo", value="Foo"): |
14 | | - "This is the Foo tab" |
15 | | - with ui.nav_menu("Static", value="tabs"): |
16 | | - with ui.nav_panel("Static 1", value="s1"): |
17 | | - "Static 1" |
18 | | - with ui.nav_panel("Static 2", value="s2"): |
19 | | - "Static 2" |
20 | | - |
21 | | - @reactive.effect() |
22 | | - @reactive.event(input.add) |
23 | | - def _(): |
24 | | - id = "Dynamic-" + str(input.add()) |
25 | | - with ui.hold() as new_panel: |
26 | | - with ui.nav_panel(id, value=id): |
27 | | - pass |
28 | | - ui.insert_nav_panel( |
29 | | - "tabs", |
30 | | - new_panel, |
31 | | - target="s2", |
32 | | - position="before", |
33 | | - ) |
34 | | - |
35 | | - @reactive.effect() |
36 | | - @reactive.event(input.removeFoo) |
37 | | - def _(): |
38 | | - ui.remove_nav_panel("set", target="Foo") |
39 | | - |
40 | | - @reactive.effect() |
41 | | - @reactive.event(input.addFoo) |
42 | | - def _(): |
43 | | - n = str(input.addFoo()) |
44 | | - with ui.hold() as new_panel: |
45 | | - with ui.nav_panel("Foo-" + n, value="Foo"): |
46 | | - "This is the new Foo-" + n + " tab" |
47 | | - ui.insert_nav_panel( |
48 | | - "tabs", |
49 | | - new_panel[0], |
50 | | - target="Menu", |
51 | | - position="before", |
52 | | - select=True, |
53 | | - ) |
| 4 | +with ui.sidebar(): |
| 5 | + ui.input_action_button("add", "Add 'Dynamic' tab") |
| 6 | + ui.input_action_button("removeFoo", "Remove 'Foo' tabs") |
| 7 | + ui.input_action_button("addFoo", "Add New 'Foo' tab") |
| 8 | + |
| 9 | +with ui.navset_tab(id="tabs"): |
| 10 | + with ui.nav_panel("Hello", value="Hello"): |
| 11 | + "This is the hello tab" |
| 12 | + with ui.nav_panel("Foo", value="Foo"): |
| 13 | + "This is the Foo tab" |
| 14 | + with ui.nav_menu("Static", value="Menu"): |
| 15 | + with ui.nav_panel("Static 1", value="s1"): |
| 16 | + "Static 1" |
| 17 | + with ui.nav_panel("Static 2", value="s2"): |
| 18 | + "Static 2" |
| 19 | + |
| 20 | + |
| 21 | +@reactive.effect() |
| 22 | +@reactive.event(input.add) |
| 23 | +def _(): |
| 24 | + id = "Dynamic-" + str(input.add()) |
| 25 | + ui.insert_nav_panel("tabs", title=id, value=id, target="s2", position="before") |
| 26 | + |
| 27 | + |
| 28 | +@reactive.effect() |
| 29 | +@reactive.event(input.removeFoo) |
| 30 | +def _(): |
| 31 | + ui.remove_nav_panel("tabs", target="Foo") |
| 32 | + |
| 33 | + |
| 34 | +@reactive.effect() |
| 35 | +@reactive.event(input.addFoo) |
| 36 | +def _(): |
| 37 | + n = str(input.addFoo()) |
| 38 | + ui.insert_nav_panel( |
| 39 | + "tabs", |
| 40 | + "Foo-" + n, |
| 41 | + "This is the new Foo-" + n + " tab", |
| 42 | + value="Foo", |
| 43 | + target="Menu", |
| 44 | + position="before", |
| 45 | + select=True, |
| 46 | + ) |
0 commit comments