|
1 | | -from shiny.express import ui |
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from shiny.express import expressify, ui |
2 | 4 |
|
3 | 5 |
|
4 | 6 | def navset_sidebar(): |
@@ -52,24 +54,50 @@ def navset_sidebar(): |
52 | 54 | ), |
53 | 55 | ] |
54 | 56 |
|
| 57 | + |
| 58 | +@expressify |
| 59 | +def navset_bar_panel(tab_name: str, navset_args: dict[str, Any]) -> None: |
| 60 | + with ui.nav_panel(tab_name): |
| 61 | + with ui.card(style="position: relative;"): |
| 62 | + navset_kwargs = navset_args.copy() |
| 63 | + navbar_options_keys = ( |
| 64 | + "position", |
| 65 | + "bg", |
| 66 | + "theme", |
| 67 | + "inverse", |
| 68 | + "collapsible", |
| 69 | + "underline", |
| 70 | + ) |
| 71 | + navbar_options_kwargs: dict[str, Any] = {} |
| 72 | + for key in navbar_options_keys: |
| 73 | + if key not in navset_kwargs: |
| 74 | + continue |
| 75 | + |
| 76 | + value = navset_kwargs.pop(key) |
| 77 | + |
| 78 | + if key == "inverse": |
| 79 | + navbar_options_kwargs["theme"] = "dark" if value else "light" |
| 80 | + else: |
| 81 | + navbar_options_kwargs[key] = value |
| 82 | + if navbar_options_kwargs: |
| 83 | + navset_kwargs["navbar_options"] = ui.navbar_options( |
| 84 | + **navbar_options_kwargs |
| 85 | + ) |
| 86 | + |
| 87 | + with ui.navset_bar(**navset_kwargs): |
| 88 | + with ui.nav_panel("A"): |
| 89 | + "Panel A content" |
| 90 | + |
| 91 | + with ui.nav_panel("B"): |
| 92 | + "Panel B content" |
| 93 | + |
| 94 | + |
55 | 95 | # Add extra spaces so that the navset_tab is below the fixed-top navset_bar |
56 | 96 | ui.br() |
57 | 97 | ui.br() |
58 | 98 | ui.br() |
59 | 99 | ui.br() |
60 | 100 |
|
61 | | -# TODO-karan; Put each navset_bar into a navpanel within a navset_tab (similar to the navsets_kitchensink app) |
62 | 101 | with ui.navset_tab(id="navsets_collection"): |
63 | 102 | for tab_name, navset_args in navset_bar_infos: |
64 | | - with ui.nav_panel(tab_name): |
65 | | - |
66 | | - with ui.card(style="position: relative;"): |
67 | | - |
68 | | - with ui.navset_bar( |
69 | | - **navset_args # pyright: ignore[reportArgumentType] |
70 | | - ): |
71 | | - with ui.nav_panel("A"): |
72 | | - "Panel A content" |
73 | | - |
74 | | - with ui.nav_panel("B"): |
75 | | - "Panel B content" |
| 103 | + navset_bar_panel(tab_name, navset_args) |
0 commit comments