Skip to content

Commit bc4a91a

Browse files
committed
Merge branch 'main' into fix/insert-accordion-panel
2 parents 7a19f4f + 6bebea5 commit bc4a91a

File tree

16 files changed

+770
-64
lines changed

16 files changed

+770
-64
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### New features
1111

12+
* Added `ui.insert_nav_panel()`, `ui.remove_nav_panel()`, and `ui.update_nav_panel()` to support dynamic navigation. (#90)
13+
1214
* Added support for python 3.13. (#1711)
1315

1416
* `ui.sidebar()` is now interactively resizable. (#2020)

docs/_quartodoc-core.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ quartodoc:
8484
- ui.navset_pill_list
8585
- ui.navset_hidden
8686
- ui.navbar_options
87+
- ui.insert_nav_panel
88+
- ui.remove_nav_panel
89+
- ui.update_nav_panel
8790
- title: UI panels
8891
desc: Visually group together a section of UI components.
8992
contents:

docs/_quartodoc-express.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ quartodoc:
7878
- express.ui.navset_pill_list
7979
- express.ui.navset_hidden
8080
- express.ui.navbar_options
81+
- express.ui.insert_nav_panel
82+
- express.ui.remove_nav_panel
83+
- express.ui.update_nav_panel
8184
- title: Chat interface
8285
desc: Build a chatbot interface
8386
contents:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from shiny import App, Inputs, Outputs, Session, reactive, ui
2+
3+
app_ui = ui.page_sidebar(
4+
ui.sidebar(
5+
ui.input_action_button("add", "Add 'Dynamic' tab"),
6+
ui.input_action_button("update_foo", "Add/Remove 'Foo' tab"),
7+
),
8+
ui.navset_tab(
9+
ui.nav_panel("Hello", "This is the hello tab", value="Hello"),
10+
ui.nav_panel("Foo", "This is the Foo tab", value="Foo"),
11+
ui.nav_menu(
12+
"Static",
13+
ui.nav_panel("Static 1", "Static 1", value="s1"),
14+
ui.nav_panel("Static 2", "Static 2", value="s2"),
15+
value="Menu",
16+
),
17+
id="tabs",
18+
),
19+
)
20+
21+
22+
def server(input: Inputs, output: Outputs, session: Session):
23+
24+
@reactive.effect
25+
@reactive.event(input.update_foo)
26+
def _():
27+
if input.update_foo() % 2 == 0:
28+
ui.insert_nav_panel(
29+
"tabs",
30+
ui.nav_panel("Foo", "Foo is back now", value="Foo"),
31+
target="Menu",
32+
position="before",
33+
select=True,
34+
)
35+
else:
36+
ui.remove_nav_panel("tabs", target="Foo")
37+
38+
@reactive.effect
39+
@reactive.event(input.add)
40+
def _():
41+
id = "Dynamic-" + str(input.add())
42+
ui.insert_nav_panel(
43+
"tabs",
44+
ui.nav_panel(id, id, value=id),
45+
target="s2",
46+
position="before",
47+
)
48+
49+
ui.notification_show(f"Added tab to menu: {id}")
50+
51+
52+
app = App(app_ui, server)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from shiny import reactive
2+
from shiny.express import input, ui
3+
4+
with ui.sidebar():
5+
ui.input_action_button("add", "Add 'Dynamic' tab")
6+
ui.input_action_button("update_foo", "Add/Remove 'Foo' tab")
7+
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.update_foo)
23+
def _():
24+
if input.update_foo() % 2 == 0:
25+
ui.insert_nav_panel(
26+
"tabs",
27+
"Foo",
28+
"Foo is back now",
29+
value="Foo",
30+
target="Menu",
31+
position="before",
32+
select=True,
33+
)
34+
else:
35+
ui.remove_nav_panel("tabs", target="Foo")
36+
37+
38+
@reactive.effect
39+
@reactive.event(input.add)
40+
def _():
41+
id = "Dynamic-" + str(input.add())
42+
ui.insert_nav_panel("tabs", title=id, value=id, target="s2", position="before")
43+
ui.notification_show(f"Added tab to menu: {id}")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from shiny import App, Inputs, Outputs, Session, reactive, ui
2+
3+
app_ui = ui.page_sidebar(
4+
ui.sidebar(
5+
"Home",
6+
ui.input_action_button("hideTab", "Hide 'Foo' tab"),
7+
ui.input_action_button("showTab", "Show 'Foo' tab"),
8+
ui.input_action_button("hideMenu", "Hide 'More' nav_menu"),
9+
ui.input_action_button("showMenu", "Show 'More' nav_menu"),
10+
),
11+
ui.navset_tab(
12+
ui.nav_panel("Foo", "This is the foo tab", value="Foo"),
13+
ui.nav_panel("Bar", "This is the bar tab", value="Bar"),
14+
ui.nav_menu(
15+
"More",
16+
ui.nav_panel("Table", "Table page"),
17+
ui.nav_panel("About", "About page"),
18+
"------",
19+
"Even more!",
20+
ui.nav_panel("Email", "Email page"),
21+
value="More",
22+
),
23+
id="tabs",
24+
),
25+
title="Navbar page",
26+
id="sidebar",
27+
)
28+
29+
30+
def server(input: Inputs, output: Outputs, session: Session):
31+
@reactive.effect
32+
@reactive.event(input.hideTab)
33+
def _():
34+
ui.update_nav_panel("tabs", target="Foo", method="hide")
35+
36+
@reactive.effect
37+
@reactive.event(input.showTab)
38+
def _():
39+
ui.update_nav_panel("tabs", target="Foo", method="show")
40+
41+
@reactive.effect
42+
@reactive.event(input.hideMenu)
43+
def _():
44+
ui.update_nav_panel("tabs", target="More", method="hide")
45+
46+
@reactive.effect
47+
@reactive.event(input.showMenu)
48+
def _():
49+
ui.update_nav_panel("tabs", target="More", method="show")
50+
51+
52+
app = App(app_ui, server)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from shiny import reactive
2+
from shiny.express import input, ui
3+
4+
with ui.layout_sidebar():
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")
11+
12+
with ui.navset_tab(id="tabs"):
13+
with ui.nav_panel("Foo", value="Foo"):
14+
"This is the foo tab"
15+
with ui.nav_panel("Bar", value="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"
26+
27+
@reactive.effect
28+
@reactive.event(input.hideTab)
29+
def _():
30+
ui.update_nav_panel("tabs", target="Foo", method="hide")
31+
32+
@reactive.effect
33+
@reactive.event(input.showTab)
34+
def _():
35+
ui.update_nav_panel("tabs", target="Foo", method="show")
36+
37+
@reactive.effect
38+
@reactive.event(input.hideMenu)
39+
def _():
40+
ui.update_nav_panel("tabs", target="More", method="hide")
41+
42+
@reactive.effect
43+
@reactive.event(input.showMenu)
44+
def _():
45+
ui.update_nav_panel("tabs", target="More", method="show")

0 commit comments

Comments
 (0)