Skip to content

Commit 3cfa66b

Browse files
committed
Updated express nav_insert
1 parent 2cf6331 commit 3cfa66b

File tree

2 files changed

+47
-54
lines changed

2 files changed

+47
-54
lines changed
Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
from shiny import reactive
22
from shiny.express import input, ui
33

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

shiny/ui/_navs_dynamic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def insert_nav_panel(
6060
--------
6161
~remove_nav_panel
6262
~show_nav_panel
63-
~nav_hide
63+
~hide_nav_panel
6464
~shiny.ui.nav_panel
6565
"""
6666

@@ -110,7 +110,7 @@ def remove_nav_panel(id: str, target: str, session: Optional[Session] = None) ->
110110
--------
111111
~insert_nav_panel
112112
~show_nav_panel
113-
~nav_hide
113+
~hide_nav_panel
114114
~shiny.ui.nav_panel
115115
"""
116116

@@ -145,11 +145,11 @@ def show_nav_panel(
145145
Note
146146
----
147147
For `show_nav_panel()` to be relevant/useful, a :func:`shiny.ui.nav` item must
148-
have been hidden using :func:`~nav_hide`.
148+
have been hidden using :func:`~hide_nav_panel`.
149149
150150
See Also
151151
--------
152-
~nav_hide
152+
~hide_nav_panel
153153
~insert_nav_panel
154154
~remove_nav_panel
155155
~shiny.ui.nav_panel

0 commit comments

Comments
 (0)