Skip to content

Commit bb5ffab

Browse files
committed
Express for nav_show works
1 parent 01c3aad commit bb5ffab

File tree

3 files changed

+76
-72
lines changed

3 files changed

+76
-72
lines changed
Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
from shiny import reactive
2-
from shiny.express import input, ui
2+
from shiny.express import input, ui, expressify, render
33

44
with ui.layout_sidebar():
55
with ui.sidebar():
66
ui.input_action_button("add", "Add 'Dynamic' tab")
77
ui.input_action_button("removeFoo", "Remove 'Foo' tabs")
88
ui.input_action_button("addFoo", "Add New 'Foo' tab")
99

10-
@reactive.effect()
11-
@reactive.event(input.removeFoo)
12-
def _():
13-
ui.nav_remove("tabs", target="Foo")
10+
with ui.navset_tab(id="set"):
11+
with ui.nav_panel("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"
1420

15-
@reactive.effect()
16-
@reactive.event(input.addFoo)
17-
def _():
18-
n = str(input.addFoo())
19-
ui.nav_insert(
20-
"tabs",
21-
ui.nav_panel(
22-
"Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"
23-
),
24-
target="Menu",
25-
position="before",
26-
select=True,
27-
)
21+
@reactive.effect()
22+
@reactive.event(input.add)
23+
def _():
24+
id = "Dynamic-" + str(input.add())
25+
ui.nav_insert(
26+
"tabs",
27+
ui.nav_panel(id, value=id),
28+
target="s2",
29+
position="before",
30+
)
2831

29-
with ui.navset_tab(id="tabs"):
30-
with ui.nav_panel("Hello"):
31-
"This is the hello tab"
32-
with ui.nav_panel("Foo", value="Foo"):
33-
"This is the Foo tab"
34-
with ui.nav_menu("Static", value="Menu"):
35-
with ui.nav_panel("Static 1", value="s1"):
36-
"Static 1"
37-
with ui.nav_panel("Static 2", value="s2"):
38-
"Static 2",
32+
@reactive.effect()
33+
@reactive.event(input.removeFoo)
34+
def _():
35+
ui.nav_remove("set", target="Foo")
3936

40-
@reactive.effect()
41-
@reactive.event(input.add)
42-
def _():
43-
id = "Dynamic-" + str(input.add())
44-
ui.nav_insert(
45-
"tabs",
46-
ui.nav_panel(id, id),
47-
target="s2",
48-
position="before",
49-
)
37+
@reactive.effect()
38+
@reactive.event(input.addFoo)
39+
def _():
40+
n = str(input.addFoo())
41+
ui.nav_insert(
42+
"tabs",
43+
ui.nav_panel("Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"),
44+
target="Menu",
45+
position="before",
46+
select=True,
47+
)
Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
from shiny import reactive
2-
from shiny.express import input, ui, expressify, render
2+
from shiny.express import input, ui
33

44
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")
5+
with ui.sidebar(title="Navbar page", id="sidebar"):
6+
"Home"
7+
ui.input_action_button("hideTab", "Hide 'Foo' tab")
8+
ui.input_action_button("showTab", "Show 'Foo' tab")
9+
ui.input_action_button("hideMenu", "Hide 'More' nav_menu")
10+
ui.input_action_button("showMenu", "Show 'More' nav_menu")
911

1012
with ui.navset_tab(id="tabs"):
11-
with ui.nav_panel("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="Menu"):
16-
with ui.nav_panel("Static 1", value="s1"):
17-
"Static 1"
18-
with ui.nav_panel("Static 2", value="s2"):
19-
"Static 2"
13+
with ui.nav_panel("Foo"):
14+
"This is the foo tab"
15+
with ui.nav_panel("Bar"):
16+
"This is the bar tab"
17+
with ui.nav_menu(title="More", value="More"):
18+
with ui.nav_panel("Table"):
19+
"Table page"
20+
with ui.nav_panel("About"):
21+
"About page"
22+
"------"
23+
"Even more!"
24+
with ui.nav_panel("Email"):
25+
"Email page"
2026

21-
@expressify()
22-
@reactive.event(input.add)
27+
@reactive.effect()
28+
@reactive.event(input.hideTab)
29+
def _():
30+
ui.nav_hide("tabs", target="Foo")
31+
32+
@reactive.effect()
33+
@reactive.event(input.showTab)
2334
def _():
24-
id = "Dynamic-" + str(input.add())
25-
ui.nav_insert(
26-
"tabs",
27-
ui.nav_panel(id, id),
28-
target="s2",
29-
position="before",
30-
)
35+
ui.nav_show("tabs", target="Foo")
3136

3237
@reactive.effect()
33-
@reactive.event(input.removeFoo)
38+
@reactive.event(input.hideMenu)
3439
def _():
35-
ui.nav_remove("tabs", target="Foo")
40+
ui.nav_hide("tabs", target="More")
3641

3742
@reactive.effect()
38-
@reactive.event(input.addFoo)
43+
@reactive.event(input.showMenu)
3944
def _():
40-
n = str(input.addFoo())
41-
ui.nav_insert(
42-
"tabs",
43-
ui.nav_panel("Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"),
44-
target="Menu",
45-
position="before",
46-
select=True,
47-
)
45+
ui.nav_show("tabs", target="More")

shiny/express/ui/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
notification_remove,
110110
nav_spacer,
111111
navbar_options,
112+
nav_hide,
113+
nav_insert,
114+
nav_remove,
115+
nav_show,
112116
Progress,
113117
Theme,
114118
value_box_theme,
@@ -289,6 +293,10 @@
289293
"navset_hidden",
290294
"navset_pill",
291295
"navset_pill_list",
296+
"nav_hide",
297+
"nav_insert",
298+
"nav_remove",
299+
"nav_show",
292300
"navset_tab",
293301
"navset_underline",
294302
"navbar_options",

0 commit comments

Comments
 (0)