-
Notifications
You must be signed in to change notification settings - Fork 114
feat: Implement dynamic navs #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
d761a5d
Implement dynamic navs (i.e., nav_insert(), nav_remove(), nav_show(),…
cpsievert 9048478
Use resolve_id instead of session.ns for id resolution in navs_dynamic
jcheng5 acde8d8
Explain how to prepend/append
jcheng5 f210d48
Merge branch 'main' into dynamic-navs
cpsievert 2799518
Modernize message sending
cpsievert 5d6cb93
Cleanup
cpsievert 24765ad
Update shiny/ui/_navs_dynamic.py
elnelson575 b32d14b
First revisions
elnelson575 1902796
Merge remote-tracking branch 'origin/dynamic-navs' into dynamic-navs
elnelson575 01c3aad
Updating nav implementation and examples
elnelson575 bb5ffab
Express for nav_show works
elnelson575 06f0d0e
Fixing formatting
elnelson575 9414879
Update nav language to say nav_panel
elnelson575 019d619
Removing unused imports
elnelson575 6de5bde
Example app with dynamic tabs
elnelson575 78f89d4
Add more ergonomic nav_insert()
cpsievert 7e57fce
Finishing visibility tests
elnelson575 6a3de97
Merge branch 'dynamic-navs' of github.com:posit-dev/py-shiny into dyn…
elnelson575 1fa58d5
PLAYWRIGHT WORKS
elnelson575 eff71c7
Removing timeout
elnelson575 2cf6331
Renaming
elnelson575 3cfa66b
Updated express nav_insert
elnelson575 b350733
Rename folders for api-examples to show up right in docs
elnelson575 f74e938
Initial untested module express example
elnelson575 4818091
Test navs
elnelson575 53e0bfe
Updating express test
elnelson575 79b0f67
Updating to update_nav_panel
elnelson575 1a2e769
Clarified test comments
elnelson575 4157551
Added string tests
elnelson575 3200c31
Isort
elnelson575 57e0540
Update shiny/api-examples/insert_nav_panel/app-core.py
elnelson575 3879029
Updating textpanels
elnelson575 238032b
Update reactive effect
elnelson575 036d38b
Updating reactive effects
elnelson575 7f0a796
updating description
elnelson575 206252b
Updating comments
elnelson575 eba940b
Update text
elnelson575 c0366a1
Update text
elnelson575 2455c31
Add example with update_navs
elnelson575 8d4f201
Update name
elnelson575 2086f4a
Updating all camelcase before .loc edits
elnelson575 5d2b391
Updating spacing
elnelson575 ea8518e
Aligning
elnelson575 41b2e5e
Add a note about menu divider/header
cpsievert 559ab2a
Updating to remove top level text render
elnelson575 b20faac
Updating to remove top level
elnelson575 748d81b
Updated tests'
elnelson575 7d4434b
Merge branch 'dynamic-navs' of github.com:posit-dev/py-shiny into dyn…
elnelson575 0c9448c
Updating tests
elnelson575 1fff229
Updating examples
elnelson575 c29710b
Adding changelog
elnelson575 5a89e2c
Minor correction
elnelson575 78b5460
Adding notifications
elnelson575 1fced93
Minor changes
elnelson575 1c77316
Merge branch 'main' into dynamic-navs
elnelson575 7ec9191
Add to API reference
cpsievert 49438c1
Make no example
cpsievert f2aad2e
adding python string
elnelson575 1deb81f
Merge branch 'dynamic-navs' of github.com:posit-dev/py-shiny into dyn…
elnelson575 d5c199e
Update docstrings
elnelson575 f28420e
Update CHANGELOG.md
elnelson575 8f0fb76
Update shiny/ui/_navs_dynamic.py
elnelson575 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from shiny import App, Inputs, Outputs, Session, reactive, ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| ui.input_action_button("add", "Add 'Dynamic' tab"), | ||
| ui.input_action_button("update_foo", "Add/Remove 'Foo' tab"), | ||
| ), | ||
| ui.navset_tab( | ||
| ui.nav_panel("Hello", "This is the hello tab", value="Hello"), | ||
| ui.nav_panel("Foo", "This is the Foo tab", value="Foo"), | ||
| ui.nav_menu( | ||
| "Static", | ||
| ui.nav_panel("Static 1", "Static 1", value="s1"), | ||
| ui.nav_panel("Static 2", "Static 2", value="s2"), | ||
| value="Menu", | ||
| ), | ||
| id="tabs", | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.update_foo) | ||
| def _(): | ||
| if input.update_foo() % 2 == 0: | ||
| ui.insert_nav_panel( | ||
| "tabs", | ||
| ui.nav_panel("Foo", "Foo is back now", value="Foo"), | ||
| target="Menu", | ||
| position="before", | ||
| select=True, | ||
| ) | ||
| else: | ||
| ui.remove_nav_panel("tabs", target="Foo") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.add) | ||
| def _(): | ||
| id = "Dynamic-" + str(input.add()) | ||
| ui.insert_nav_panel( | ||
| "tabs", | ||
| ui.nav_panel(id, id, value=id), | ||
| target="s2", | ||
| position="before", | ||
| ) | ||
|
|
||
| ui.notification_show(f"Added tab to menu: {id}") | ||
|
|
||
|
|
||
| app = App(app_ui, server) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from shiny import reactive | ||
| from shiny.express import input, ui | ||
|
|
||
| with ui.sidebar(): | ||
| ui.input_action_button("add", "Add 'Dynamic' tab") | ||
| ui.input_action_button("update_foo", "Add/Remove 'Foo' tab") | ||
|
|
||
|
|
||
| with ui.navset_tab(id="tabs"): | ||
| with ui.nav_panel("Hello", value="Hello"): | ||
| "This is the hello tab" | ||
| with ui.nav_panel("Foo", value="Foo"): | ||
| "This is the Foo tab" | ||
| with ui.nav_menu("Static", value="Menu"): | ||
| with ui.nav_panel("Static 1", value="s1"): | ||
| "Static 1" | ||
| with ui.nav_panel("Static 2", value="s2"): | ||
| "Static 2" | ||
|
|
||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.update_foo) | ||
| def _(): | ||
| if input.update_foo() % 2 == 0: | ||
| ui.insert_nav_panel( | ||
| "tabs", | ||
| "Foo", | ||
| "Foo is back now", | ||
| value="Foo", | ||
| target="Menu", | ||
| position="before", | ||
| select=True, | ||
| ) | ||
| else: | ||
| ui.remove_nav_panel("tabs", target="Foo") | ||
|
|
||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.add) | ||
| def _(): | ||
| id = "Dynamic-" + str(input.add()) | ||
| ui.insert_nav_panel("tabs", title=id, value=id, target="s2", position="before") | ||
cpsievert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ui.notification_show(f"Added tab to menu: {id}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from shiny import App, Inputs, Outputs, Session, reactive, ui | ||
|
|
||
| app_ui = ui.page_sidebar( | ||
| ui.sidebar( | ||
| "Home", | ||
| ui.input_action_button("hideTab", "Hide 'Foo' tab"), | ||
| ui.input_action_button("showTab", "Show 'Foo' tab"), | ||
| ui.input_action_button("hideMenu", "Hide 'More' nav_menu"), | ||
| ui.input_action_button("showMenu", "Show 'More' nav_menu"), | ||
| ), | ||
| ui.navset_tab( | ||
| ui.nav_panel("Foo", "This is the foo tab", value="Foo"), | ||
| ui.nav_panel("Bar", "This is the bar tab", value="Bar"), | ||
| ui.nav_menu( | ||
| "More", | ||
| ui.nav_panel("Table", "Table page"), | ||
| ui.nav_panel("About", "About page"), | ||
| "------", | ||
| "Even more!", | ||
| ui.nav_panel("Email", "Email page"), | ||
| value="More", | ||
| ), | ||
| id="tabs", | ||
| ), | ||
| title="Navbar page", | ||
| id="sidebar", | ||
| ) | ||
|
|
||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
| @reactive.effect | ||
| @reactive.event(input.hideTab) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="Foo", method="hide") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.showTab) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="Foo", method="show") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.hideMenu) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="More", method="hide") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.showMenu) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="More", method="show") | ||
|
|
||
|
|
||
| app = App(app_ui, server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| from shiny import reactive | ||
| from shiny.express import input, ui | ||
|
|
||
| with ui.layout_sidebar(): | ||
| with ui.sidebar(title="Navbar page", id="sidebar"): | ||
| "Home" | ||
| ui.input_action_button("hideTab", "Hide 'Foo' tab") | ||
| ui.input_action_button("showTab", "Show 'Foo' tab") | ||
| ui.input_action_button("hideMenu", "Hide 'More' nav_menu") | ||
| ui.input_action_button("showMenu", "Show 'More' nav_menu") | ||
|
|
||
| with ui.navset_tab(id="tabs"): | ||
| with ui.nav_panel("Foo", value="Foo"): | ||
| "This is the foo tab" | ||
| with ui.nav_panel("Bar", value="Bar"): | ||
| "This is the bar tab" | ||
| with ui.nav_menu(title="More", value="More"): | ||
| with ui.nav_panel("Table"): | ||
| "Table page" | ||
| with ui.nav_panel("About"): | ||
| "About page" | ||
| "------" | ||
| "Even more!" | ||
| with ui.nav_panel("Email"): | ||
| "Email page" | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.hideTab) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="Foo", method="hide") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.showTab) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="Foo", method="show") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.hideMenu) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="More", method="hide") | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.showMenu) | ||
| def _(): | ||
| ui.update_nav_panel("tabs", target="More", method="show") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Shims for `ui.insert_*()`, `ui.update_*()`, etc. functions that lead to a more ergonomic | ||
| Express API. | ||
| These functions tend to have one issue in common: if they were re-exported verbatim from | ||
| Core to Express, they would want to take RecallContextManager(s) as input, which leads | ||
| to a somewhat awkward API. That's because, you'd have to know to use something like | ||
| @ui.hold() pass the UI as a value without displaying it. | ||
| """ | ||
|
|
||
| from typing import Literal, Optional | ||
|
|
||
| from htmltools import TagChild | ||
|
|
||
| from ..._docstring import add_example | ||
| from ...session import Session | ||
|
|
||
|
|
||
| @add_example() | ||
| def insert_nav_panel( | ||
| id: str, | ||
| title: TagChild, | ||
| *args: TagChild, | ||
| value: Optional[str] = None, | ||
| icon: TagChild = None, | ||
| target: Optional[str] = None, | ||
| position: Literal["after", "before"] = "after", | ||
| select: bool = False, | ||
| session: Optional[Session] = None, | ||
| ) -> None: | ||
| """ | ||
| Create a new nav panel in an existing navset. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| id | ||
| The id of the navset container to insert into. | ||
| title | ||
| A title for the inserted nav panel. Can be a character string or UI elements (i.e., tags). | ||
| *args | ||
| UI elements for the inserted nav panel. | ||
| value | ||
| The value of the panel. Use this value to determine whether the panel is active | ||
| (when an `id` is provided to the nav container) or to programmatically | ||
| select the item (e.g., :func:`~shiny.ui.update_navs`). You can also | ||
| provide the value to the `selected` argument of the navigation container | ||
| (e.g., :func:`~shiny.ui.navset_tab`). | ||
| icon | ||
| An icon to appear inline with the title. | ||
| target | ||
| The `value` of an existing :func:`shiny.ui.nav_panel`, next to which tab will | ||
| be added. Can also be `None`; see `position`. | ||
| position | ||
| The position of the new nav panel relative to the target. If | ||
| `target=None`, then `"before"` means the new panel should be inserted at | ||
| the head of the navlist, and `"after"` is the end. | ||
| select | ||
| Whether the nav panel should be selected upon insertion. | ||
| session | ||
| A :class:`~shiny.Session` instance. If not provided, it is inferred via | ||
| :func:`~shiny.session.get_current_session`. | ||
|
|
||
| Note | ||
| ---- | ||
| Unlike :func:`~shiny.ui.insert_nav_panel`, this function does not support inserting | ||
| of a heading/divider into an existing :func:`~shiny.ui.nav_menu`. To do so, use | ||
| :func:`~shiny.ui.insert_nav_panel` instead of this Express variant (i.e., | ||
| `shiny.ui.insert_nav_panel("id", "Header")`). | ||
| """ | ||
|
|
||
| from ...ui import insert_nav_panel, nav_panel | ||
|
|
||
| panel = nav_panel( | ||
| title, | ||
| *args, | ||
| value=value, | ||
| icon=icon, | ||
| ) | ||
|
|
||
| insert_nav_panel( | ||
| id=id, | ||
| nav_panel=panel, | ||
| target=target, | ||
| position=position, | ||
| select=select, | ||
| session=session, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.