Skip to content

Commit 1651445

Browse files
authored
docs(navset): Add server function to navset docs (posit-dev#1596)
1 parent 9f1f751 commit 1651445

File tree

23 files changed

+174
-152
lines changed

23 files changed

+174
-152
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from shiny import App, ui
1+
from shiny import App, render, ui
22

33
app_ui = ui.page_fluid(
44
ui.navset_card_pill(
@@ -8,13 +8,17 @@
88
ui.nav_panel("B", "Panel B content"),
99
ui.nav_panel("C", "Panel C content"),
1010
),
11-
id="card_pill",
11+
id="selected_card_pill",
1212
),
13+
ui.h5("Selected:"),
14+
ui.output_code("selected"),
1315
)
1416

1517

1618
def server(input, output, session):
17-
pass
19+
@render.code
20+
def selected():
21+
return input.selected_card_pill()
1822

1923

2024
app = App(app_ui, server)
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
from shiny.express import ui
1+
from shiny.express import input, render, ui
22

3-
with ui.navset_card_pill(id="card_pill"):
3+
with ui.navset_card_pill(id="selected_card_pill"):
44
with ui.nav_menu("Nav Menu items"):
55
with ui.nav_panel("A"):
66
"Page A content"
77
with ui.nav_panel("B"):
88
"Page B content"
99
with ui.nav_panel("C"):
1010
"Page C content"
11+
ui.h5("Selected:")
12+
13+
14+
@render.code
15+
def _():
16+
return input.selected_card_pill()

shiny/api-examples/nav_panel/app-basic.py

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,23 @@
1-
from typing import List
2-
3-
from shiny import App, Inputs, Outputs, Session, reactive, ui
4-
from shiny.types import NavSetArg
5-
6-
7-
def nav_controls(prefix: str) -> List[NavSetArg]:
8-
return [
9-
ui.nav_panel("a", prefix + ": tab a content"),
10-
ui.nav_panel("b", prefix + ": tab b content"),
11-
ui.nav_panel("c", prefix + ": tab c content"),
12-
ui.nav_spacer(),
13-
ui.nav_menu(
14-
"Links",
15-
ui.nav_control(
16-
ui.a(
17-
"Shiny",
18-
href="https://shiny.posit.co/py/",
19-
target="_blank",
20-
)
21-
),
22-
"----",
23-
"Plain text",
24-
"----",
25-
ui.nav_control(
26-
ui.a(
27-
"Posit",
28-
href="https://posit.co",
29-
target="_blank",
30-
)
1+
from shiny import App, Inputs, ui
2+
3+
app_ui = ui.page_fluid(
4+
ui.navset_bar(
5+
ui.nav_panel("Page 1", "Page 1 content"),
6+
ui.nav_panel(
7+
"Page 2",
8+
ui.navset_card_underline(
9+
ui.nav_panel("Tab 1", "Tab 1 content"),
10+
ui.nav_panel("Tab 2", "Tab 2 content"),
11+
ui.nav_panel("Tab 3", "Tab 3 content"),
3112
),
32-
align="right",
33-
),
34-
]
35-
36-
37-
app_ui = ui.page_navbar(
38-
*nav_controls("page_navbar"),
39-
title="page_navbar()",
40-
id="navbar_id",
41-
footer=ui.div(
42-
{"style": "width:80%;margin: 0 auto"},
43-
ui.tags.style(
44-
"""
45-
h4 {
46-
margin-top: 3em;
47-
}
48-
"""
4913
),
50-
ui.h4("navset_tab()"),
51-
ui.navset_tab(*nav_controls("navset_tab()")),
52-
ui.h4("navset_pill()"),
53-
ui.navset_pill(*nav_controls("navset_pill()")),
54-
ui.h4("navset_underline()"),
55-
ui.navset_underline(*nav_controls("navset_underline()")),
56-
ui.h4("navset_card_tab()"),
57-
ui.navset_card_tab(*nav_controls("navset_card_tab()")),
58-
ui.h4("navset_card_pill()"),
59-
ui.navset_card_pill(*nav_controls("navset_card_pill()")),
60-
ui.h4("navset_card_underline()"),
61-
ui.navset_card_underline(*nav_controls("navset_card_underline()")),
62-
ui.h4("navset_pill_list()"),
63-
ui.navset_pill_list(*nav_controls("navset_pill_list()")),
64-
)
14+
title="Nav Panel Example",
15+
),
6516
)
6617

6718

68-
def server(input: Inputs, output: Outputs, session: Session):
69-
@reactive.effect
70-
def _():
71-
print("Current navbar page: ", input.navbar_id())
19+
def server(input: Inputs):
20+
pass
7221

7322

7423
app = App(app_ui, server)

shiny/api-examples/nav_panel/app-express.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,3 @@
1313
"Tab 2 content"
1414
with ui.nav_panel("Tab 3"):
1515
"Tab 3 content"
16-
17-
ui.nav_spacer()
18-
19-
with ui.nav_menu("Links", align="right"):
20-
with ui.nav_control():
21-
ui.a("Shiny", href="https://shiny.posit.co/py/", target="_blank")
22-
"----"
23-
"Plain text"
24-
"----"
25-
with ui.nav_control():
26-
ui.a("Posit", href="https://posit.co", target="_blank")
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
from shiny import App, ui
1+
from shiny import App, render, ui
22

33
app_ui = ui.page_fluid(
44
ui.navset_underline(
55
ui.nav_panel("A", "Panel A content"),
66
ui.nav_spacer(),
77
ui.nav_panel("B", "Panel B content"),
88
ui.nav_panel("C", "Panel C content"),
9-
id="navset_underline",
10-
)
9+
id="selected_navset_underline",
10+
),
11+
ui.h5("Selected:"),
12+
ui.output_code("selected"),
1113
)
1214

1315

1416
def server(input, output, session):
15-
pass
17+
@render.code
18+
def selected():
19+
return input.selected_navset_underline()
1620

1721

1822
app = App(app_ui, server)
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
from shiny.express import ui
1+
from shiny.express import input, render, ui
22

3-
with ui.navset_underline():
3+
with ui.navset_underline(id="selected_navset_underline"):
44
with ui.nav_panel("Tab 1"):
55
"Tab 1 content"
66
ui.nav_spacer()
77
with ui.nav_panel("Tab 2"):
88
"Tab 2 content"
99
with ui.nav_panel("Tab 3"):
1010
"Tab 3 content"
11+
ui.h5("Selected:")
12+
13+
14+
@render.code
15+
def _():
16+
return input.selected_navset_underline()

shiny/api-examples/navset_bar/app-core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from shiny import App, ui
1+
from shiny import App, render, ui
22

33
app_ui = ui.page_fluid(
44
ui.navset_bar(
@@ -14,14 +14,18 @@
1414
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
1515
),
1616
),
17-
id="tab",
17+
id="selected_navset_bar",
1818
title="Navset Bar",
19-
)
19+
),
20+
ui.h5("Selected:"),
21+
ui.output_code("selected"),
2022
)
2123

2224

2325
def server(input, output, session):
24-
pass
26+
@render.code
27+
def selected():
28+
return input.selected_navset_bar()
2529

2630

2731
app = App(app_ui, server)

shiny/api-examples/navset_bar/app-express.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from shiny.express import ui
1+
from shiny.express import input, render, ui
22

3-
with ui.navset_bar(title="Navset Bar", id="tab"):
3+
with ui.navset_bar(title="Navset Bar", id="selected_navset_bar"):
44
with ui.nav_panel("A"):
55
"Panel A content"
66

@@ -18,3 +18,9 @@
1818
"Description:"
1919
with ui.nav_control():
2020
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
21+
ui.h5("Selected:")
22+
23+
24+
@render.code
25+
def _():
26+
return input.selected_navset_bar()

shiny/api-examples/navset_card_pill/app-core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from shiny import App, ui
1+
from shiny import App, render, ui
22

33
app_ui = ui.page_fluid(
44
ui.navset_card_pill(
@@ -14,13 +14,17 @@
1414
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
1515
),
1616
),
17-
id="tab",
18-
)
17+
id="selected_navset_card_pill",
18+
),
19+
ui.h5("Selected:"),
20+
ui.output_code("selected"),
1921
)
2022

2123

2224
def server(input, output, session):
23-
pass
25+
@render.code
26+
def selected():
27+
return input.selected_navset_card_pill()
2428

2529

2630
app = App(app_ui, server)

0 commit comments

Comments
 (0)