From 1651445f82acdccbc3fd35d6b18c6a297d375f43 Mon Sep 17 00:00:00 2001 From: Karan Date: Thu, 22 Aug 2024 13:05:02 -0700 Subject: [PATCH] docs(navset): Add server function to navset docs (#1596) --- shiny/api-examples/nav_menu/app-core.py | 10 ++- shiny/api-examples/nav_menu/app-express.py | 10 ++- shiny/api-examples/nav_panel/app-basic.py | 16 ---- shiny/api-examples/nav_panel/app-core.py | 81 ++++--------------- shiny/api-examples/nav_panel/app-express.py | 11 --- shiny/api-examples/nav_spacer/app-core.py | 12 ++- shiny/api-examples/nav_spacer/app-express.py | 10 ++- shiny/api-examples/navset_bar/app-core.py | 12 ++- shiny/api-examples/navset_bar/app-express.py | 10 ++- .../api-examples/navset_card_pill/app-core.py | 12 ++- .../navset_card_pill/app-express.py | 10 ++- .../api-examples/navset_card_tab/app-core.py | 12 ++- .../navset_card_tab/app-express.py | 10 ++- .../navset_card_underline/app-core.py | 12 ++- .../navset_card_underline/app-express.py | 10 ++- shiny/api-examples/navset_pill/app-core.py | 12 ++- shiny/api-examples/navset_pill/app-express.py | 10 ++- .../api-examples/navset_pill_list/app-core.py | 12 ++- .../navset_pill_list/app-express.py | 10 ++- shiny/api-examples/navset_tab/app-core.py | 12 ++- shiny/api-examples/navset_tab/app-express.py | 10 ++- .../api-examples/navset_underline/app-core.py | 12 ++- .../navset_underline/app-express.py | 10 ++- 23 files changed, 174 insertions(+), 152 deletions(-) delete mode 100644 shiny/api-examples/nav_panel/app-basic.py diff --git a/shiny/api-examples/nav_menu/app-core.py b/shiny/api-examples/nav_menu/app-core.py index 3b96625e7..cb73786e1 100644 --- a/shiny/api-examples/nav_menu/app-core.py +++ b/shiny/api-examples/nav_menu/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_card_pill( @@ -8,13 +8,17 @@ ui.nav_panel("B", "Panel B content"), ui.nav_panel("C", "Panel C content"), ), - id="card_pill", + id="selected_card_pill", ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_card_pill() app = App(app_ui, server) diff --git a/shiny/api-examples/nav_menu/app-express.py b/shiny/api-examples/nav_menu/app-express.py index 50d70e552..2fe4e3a31 100644 --- a/shiny/api-examples/nav_menu/app-express.py +++ b/shiny/api-examples/nav_menu/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_card_pill(id="card_pill"): +with ui.navset_card_pill(id="selected_card_pill"): with ui.nav_menu("Nav Menu items"): with ui.nav_panel("A"): "Page A content" @@ -8,3 +8,9 @@ "Page B content" with ui.nav_panel("C"): "Page C content" +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_card_pill() diff --git a/shiny/api-examples/nav_panel/app-basic.py b/shiny/api-examples/nav_panel/app-basic.py deleted file mode 100644 index bc5b797c2..000000000 --- a/shiny/api-examples/nav_panel/app-basic.py +++ /dev/null @@ -1,16 +0,0 @@ -from shiny import App, Inputs, ui - -app_ui = ui.page_fixed( - ui.panel_title("Basic Nav Example"), - ui.navset_tab( - ui.nav_panel("One", "First tab content."), - ui.nav_panel("Two", "Second tab content."), - ), -) - - -def server(input: Inputs): - pass - - -app = App(app_ui, server) diff --git a/shiny/api-examples/nav_panel/app-core.py b/shiny/api-examples/nav_panel/app-core.py index db7650f65..00f9a9768 100644 --- a/shiny/api-examples/nav_panel/app-core.py +++ b/shiny/api-examples/nav_panel/app-core.py @@ -1,74 +1,23 @@ -from typing import List - -from shiny import App, Inputs, Outputs, Session, reactive, ui -from shiny.types import NavSetArg - - -def nav_controls(prefix: str) -> List[NavSetArg]: - return [ - ui.nav_panel("a", prefix + ": tab a content"), - ui.nav_panel("b", prefix + ": tab b content"), - ui.nav_panel("c", prefix + ": tab c content"), - ui.nav_spacer(), - ui.nav_menu( - "Links", - ui.nav_control( - ui.a( - "Shiny", - href="https://shiny.posit.co/py/", - target="_blank", - ) - ), - "----", - "Plain text", - "----", - ui.nav_control( - ui.a( - "Posit", - href="https://posit.co", - target="_blank", - ) +from shiny import App, Inputs, ui + +app_ui = ui.page_fluid( + ui.navset_bar( + ui.nav_panel("Page 1", "Page 1 content"), + ui.nav_panel( + "Page 2", + ui.navset_card_underline( + ui.nav_panel("Tab 1", "Tab 1 content"), + ui.nav_panel("Tab 2", "Tab 2 content"), + ui.nav_panel("Tab 3", "Tab 3 content"), ), - align="right", - ), - ] - - -app_ui = ui.page_navbar( - *nav_controls("page_navbar"), - title="page_navbar()", - id="navbar_id", - footer=ui.div( - {"style": "width:80%;margin: 0 auto"}, - ui.tags.style( - """ - h4 { - margin-top: 3em; - } - """ ), - ui.h4("navset_tab()"), - ui.navset_tab(*nav_controls("navset_tab()")), - ui.h4("navset_pill()"), - ui.navset_pill(*nav_controls("navset_pill()")), - ui.h4("navset_underline()"), - ui.navset_underline(*nav_controls("navset_underline()")), - ui.h4("navset_card_tab()"), - ui.navset_card_tab(*nav_controls("navset_card_tab()")), - ui.h4("navset_card_pill()"), - ui.navset_card_pill(*nav_controls("navset_card_pill()")), - ui.h4("navset_card_underline()"), - ui.navset_card_underline(*nav_controls("navset_card_underline()")), - ui.h4("navset_pill_list()"), - ui.navset_pill_list(*nav_controls("navset_pill_list()")), - ) + title="Nav Panel Example", + ), ) -def server(input: Inputs, output: Outputs, session: Session): - @reactive.effect - def _(): - print("Current navbar page: ", input.navbar_id()) +def server(input: Inputs): + pass app = App(app_ui, server) diff --git a/shiny/api-examples/nav_panel/app-express.py b/shiny/api-examples/nav_panel/app-express.py index a5d57a81b..fcb4016fa 100644 --- a/shiny/api-examples/nav_panel/app-express.py +++ b/shiny/api-examples/nav_panel/app-express.py @@ -13,14 +13,3 @@ "Tab 2 content" with ui.nav_panel("Tab 3"): "Tab 3 content" - -ui.nav_spacer() - -with ui.nav_menu("Links", align="right"): - with ui.nav_control(): - ui.a("Shiny", href="https://shiny.posit.co/py/", target="_blank") - "----" - "Plain text" - "----" - with ui.nav_control(): - ui.a("Posit", href="https://posit.co", target="_blank") diff --git a/shiny/api-examples/nav_spacer/app-core.py b/shiny/api-examples/nav_spacer/app-core.py index fb53616be..271105e2c 100644 --- a/shiny/api-examples/nav_spacer/app-core.py +++ b/shiny/api-examples/nav_spacer/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_underline( @@ -6,13 +6,17 @@ ui.nav_spacer(), ui.nav_panel("B", "Panel B content"), ui.nav_panel("C", "Panel C content"), - id="navset_underline", - ) + id="selected_navset_underline", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_underline() app = App(app_ui, server) diff --git a/shiny/api-examples/nav_spacer/app-express.py b/shiny/api-examples/nav_spacer/app-express.py index 555697a77..dd9b2e806 100644 --- a/shiny/api-examples/nav_spacer/app-express.py +++ b/shiny/api-examples/nav_spacer/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_underline(): +with ui.navset_underline(id="selected_navset_underline"): with ui.nav_panel("Tab 1"): "Tab 1 content" ui.nav_spacer() @@ -8,3 +8,9 @@ "Tab 2 content" with ui.nav_panel("Tab 3"): "Tab 3 content" +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_underline() diff --git a/shiny/api-examples/navset_bar/app-core.py b/shiny/api-examples/navset_bar/app-core.py index fbfd47e75..403e903f3 100644 --- a/shiny/api-examples/navset_bar/app-core.py +++ b/shiny/api-examples/navset_bar/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_bar( @@ -14,14 +14,18 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", + id="selected_navset_bar", title="Navset Bar", - ) + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_bar() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_bar/app-express.py b/shiny/api-examples/navset_bar/app-express.py index 8ca935e0e..8e42d5e6e 100644 --- a/shiny/api-examples/navset_bar/app-express.py +++ b/shiny/api-examples/navset_bar/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_bar(title="Navset Bar", id="tab"): +with ui.navset_bar(title="Navset Bar", id="selected_navset_bar"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_bar() diff --git a/shiny/api-examples/navset_card_pill/app-core.py b/shiny/api-examples/navset_card_pill/app-core.py index b88bb0197..96df36430 100644 --- a/shiny/api-examples/navset_card_pill/app-core.py +++ b/shiny/api-examples/navset_card_pill/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_card_pill( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_card_pill", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_card_pill() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_card_pill/app-express.py b/shiny/api-examples/navset_card_pill/app-express.py index d934b5cbe..cf6354d76 100644 --- a/shiny/api-examples/navset_card_pill/app-express.py +++ b/shiny/api-examples/navset_card_pill/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_card_pill(id="tab"): +with ui.navset_card_pill(id="selected_navset_card_pill"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_card_pill() diff --git a/shiny/api-examples/navset_card_tab/app-core.py b/shiny/api-examples/navset_card_tab/app-core.py index d314ddb35..b42445bd8 100644 --- a/shiny/api-examples/navset_card_tab/app-core.py +++ b/shiny/api-examples/navset_card_tab/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_card_tab( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_card_tab", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_card_tab() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_card_tab/app-express.py b/shiny/api-examples/navset_card_tab/app-express.py index 97c3f0570..09fb15fb9 100644 --- a/shiny/api-examples/navset_card_tab/app-express.py +++ b/shiny/api-examples/navset_card_tab/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_card_tab(id="tab"): +with ui.navset_card_tab(id="selected_navset_card_tab"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_card_tab() diff --git a/shiny/api-examples/navset_card_underline/app-core.py b/shiny/api-examples/navset_card_underline/app-core.py index 40996cb64..f65caa8cc 100644 --- a/shiny/api-examples/navset_card_underline/app-core.py +++ b/shiny/api-examples/navset_card_underline/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_card_underline( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_card_underline", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_card_underline() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_card_underline/app-express.py b/shiny/api-examples/navset_card_underline/app-express.py index 467acc081..64ea19dc1 100644 --- a/shiny/api-examples/navset_card_underline/app-express.py +++ b/shiny/api-examples/navset_card_underline/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_card_underline(id="tab"): +with ui.navset_card_underline(id="selected_navset_card_underline"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_card_underline() diff --git a/shiny/api-examples/navset_pill/app-core.py b/shiny/api-examples/navset_pill/app-core.py index 4be31b113..defaab604 100644 --- a/shiny/api-examples/navset_pill/app-core.py +++ b/shiny/api-examples/navset_pill/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_pill( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_pill", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_pill() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_pill/app-express.py b/shiny/api-examples/navset_pill/app-express.py index b367d5072..e8c3b6dea 100644 --- a/shiny/api-examples/navset_pill/app-express.py +++ b/shiny/api-examples/navset_pill/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_pill(id="tab"): +with ui.navset_pill(id="selected_navset_pill"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_pill() diff --git a/shiny/api-examples/navset_pill_list/app-core.py b/shiny/api-examples/navset_pill_list/app-core.py index f67349883..6574e7a5b 100644 --- a/shiny/api-examples/navset_pill_list/app-core.py +++ b/shiny/api-examples/navset_pill_list/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_pill_list( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_pill_list", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_pill_list() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_pill_list/app-express.py b/shiny/api-examples/navset_pill_list/app-express.py index 38b961593..dcfbac1cf 100644 --- a/shiny/api-examples/navset_pill_list/app-express.py +++ b/shiny/api-examples/navset_pill_list/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_pill_list(id="tab"): +with ui.navset_pill_list(id="selected_navset_pill_list"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_pill_list() diff --git a/shiny/api-examples/navset_tab/app-core.py b/shiny/api-examples/navset_tab/app-core.py index bbabfb320..e57788c1c 100644 --- a/shiny/api-examples/navset_tab/app-core.py +++ b/shiny/api-examples/navset_tab/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_tab( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_tab", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_tab() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_tab/app-express.py b/shiny/api-examples/navset_tab/app-express.py index 1b49ce692..b0d57f032 100644 --- a/shiny/api-examples/navset_tab/app-express.py +++ b/shiny/api-examples/navset_tab/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_tab(id="tab"): +with ui.navset_tab(id="selected_navset_tab"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_tab() diff --git a/shiny/api-examples/navset_underline/app-core.py b/shiny/api-examples/navset_underline/app-core.py index 06f67de4b..e3e43ab84 100644 --- a/shiny/api-examples/navset_underline/app-core.py +++ b/shiny/api-examples/navset_underline/app-core.py @@ -1,4 +1,4 @@ -from shiny import App, ui +from shiny import App, render, ui app_ui = ui.page_fluid( ui.navset_underline( @@ -14,13 +14,17 @@ ui.a("Shiny", href="https://shiny.posit.co", target="_blank") ), ), - id="tab", - ) + id="selected_navset_underline", + ), + ui.h5("Selected:"), + ui.output_code("selected"), ) def server(input, output, session): - pass + @render.code + def selected(): + return input.selected_navset_underline() app = App(app_ui, server) diff --git a/shiny/api-examples/navset_underline/app-express.py b/shiny/api-examples/navset_underline/app-express.py index 0868fc6e6..6a4d05685 100644 --- a/shiny/api-examples/navset_underline/app-express.py +++ b/shiny/api-examples/navset_underline/app-express.py @@ -1,6 +1,6 @@ -from shiny.express import ui +from shiny.express import input, render, ui -with ui.navset_underline(id="tab"): +with ui.navset_underline(id="selected_navset_underline"): with ui.nav_panel("A"): "Panel A content" @@ -18,3 +18,9 @@ "Description:" with ui.nav_control(): ui.a("Shiny", href="https://shiny.posit.co", target="_blank") +ui.h5("Selected:") + + +@render.code +def _(): + return input.selected_navset_underline()