Skip to content

Commit b32d14b

Browse files
committed
First revisions
1 parent 5d6cb93 commit b32d14b

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

shiny/examples/nav_insert/app.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
from shiny import *
1+
from shiny import App, Inputs, Outputs, Session, reactive, ui
22

3-
app_ui = ui.page_fluid(
4-
ui.layout_sidebar(
5-
ui.panel_sidebar(
6-
ui.input_action_button("add", "Add 'Dynamic' tab"),
7-
ui.input_action_button("removeFoo", "Remove 'Foo' tabs"),
8-
ui.input_action_button("addFoo", "Add New 'Foo' tab"),
3+
app_ui = ui.page_sidebar(
4+
ui.sidebar(
5+
ui.input_action_button("add", "Add 'Dynamic' tab"),
6+
ui.input_action_button("removeFoo", "Remove 'Foo' tabs"),
7+
ui.input_action_button("addFoo", "Add New 'Foo' tab"),
8+
),
9+
ui.navset_tab(
10+
ui.nav_panel("Hello", "This is the hello tab"),
11+
ui.nav_panel("Foo", "This is the Foo tab", value="Foo"),
12+
ui.nav_menu(
13+
"Static",
14+
ui.nav_panel("Static 1", "Static 1", value="s1"),
15+
ui.nav_panel("Static 2", "Static 2", value="s2"),
16+
value="Menu",
917
),
10-
ui.panel_main(
11-
ui.navset_tab(
12-
ui.nav("Hello", "This is the hello tab"),
13-
ui.nav("Foo", "This is the Foo tab", value="Foo"),
14-
ui.nav_menu(
15-
"Static",
16-
ui.nav("Static 1", "Static 1", value="s1"),
17-
ui.nav("Static 2", "Static 2", value="s2"),
18-
value="Menu",
19-
),
20-
id="tabs",
21-
),
22-
),
23-
)
18+
id="tabs",
19+
),
2420
)
2521

2622

2723
def server(input: Inputs, output: Outputs, session: Session):
28-
@reactive.Effect()
29-
@event(input.add)
24+
@reactive.effect()
25+
@reactive.event(input.add)
3026
def _():
3127
id = "Dynamic-" + str(input.add())
3228
ui.nav_insert(
3329
"tabs",
34-
ui.nav(id, id),
30+
ui.nav_panel(id, id),
3531
target="s2",
3632
position="before",
3733
)
3834

39-
@reactive.Effect()
40-
@event(input.removeFoo)
35+
@reactive.effect()
36+
@reactive.event(input.removeFoo)
4137
def _():
4238
ui.nav_remove("tabs", target="Foo")
4339

44-
@reactive.Effect()
45-
@event(input.addFoo)
40+
@reactive.effect()
41+
@reactive.event(input.addFoo)
4642
def _():
4743
n = str(input.addFoo())
4844
ui.nav_insert(
4945
"tabs",
50-
ui.nav("Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"),
46+
ui.nav_panel("Foo-" + n, "This is the new Foo-" + n + " tab", value="Foo"),
5147
target="Menu",
5248
position="before",
5349
select=True,

shiny/ui/_navs_dynamic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@add_example()
2525
def nav_insert(
2626
id: str,
27-
nav: Union[NavSetArg, str],
27+
nav_panel: Union[NavSetArg, str],
2828
target: Optional[str] = None,
2929
position: Literal["after", "before"] = "after",
3030
select: bool = False,
@@ -37,8 +37,8 @@ def nav_insert(
3737
----------
3838
id
3939
The ``id`` of the relevant navigation container (i.e., ``navset_*()`` object).
40-
nav
41-
The navigation item to insert (typically a :func:`~shiny.ui.nav` or
40+
nav_panel
41+
The navigation item to insert (typically a :func:`~shiny.ui.nav_panel` or
4242
:func:`~shiny.ui.nav_menu`). A :func:`~shiny.ui.nav_menu` isn't allowed when the
4343
``target`` references an :func:`~shiny.ui.nav_menu` (or an item within it). A
4444
string is only allowed when the ``target`` references a
@@ -69,9 +69,11 @@ def nav_insert(
6969
# N.B. this is only sensible if the target is a menu, but we don't know that,
7070
# which could cause confusion of we decide to support top-level strings at some
7171
# in the future.
72-
if isinstance(nav, str):
73-
nav = menu_string_as_nav(nav)
74-
72+
# print("IS INSTANCE: ", isinstance(nav_panel, str))
73+
# if isinstance(nav_panel, str):
74+
# print("isnav")
75+
nav = menu_string_as_nav(nav_panel)
76+
print(nav)
7577
# N.B. shiny.js' is smart enough to know how to add active classes and href/id attrs
7678
li_tag, div_tag = nav.resolve(
7779
selected=None, context=dict(tabsetid="tsid", index="id")

0 commit comments

Comments
 (0)