Skip to content

Commit 6a3de97

Browse files
committed
Merge branch 'dynamic-navs' of github.com:posit-dev/py-shiny into dynamic-navs
2 parents 7e57fce + 78f89d4 commit 6a3de97

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

shiny/express/ui/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@
165165
hold,
166166
)
167167

168+
from ._insert import (
169+
nav_insert,
170+
)
171+
168172
__all__ = (
169173
# Imports from htmltools
170174
"TagList",
@@ -294,7 +298,6 @@
294298
"navset_pill",
295299
"navset_pill_list",
296300
"nav_hide",
297-
"nav_insert",
298301
"nav_remove",
299302
"nav_show",
300303
"navset_tab",

shiny/express/ui/_insert.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
Shims for `ui.insert_*()`, `ui.update_*()`, etc. functions that lead to a more ergonomic
3+
Express API.
4+
These functions tend to have one issue in common: if they were re-exported verbatim from
5+
Core to Express, they would want to take RecallContextManager(s) as input, which leads
6+
to a somewhat awkward API. That's because, you'd have to know to use something like
7+
@ui.hold() pass the UI as a value without displaying it.
8+
"""
9+
10+
from typing import Literal, Optional
11+
12+
from htmltools import TagChild
13+
14+
from ..._docstring import add_example
15+
from ...session import Session
16+
17+
18+
@add_example()
19+
def nav_insert(
20+
id: str,
21+
title: str,
22+
*args: TagChild,
23+
value: Optional[str] = None,
24+
icon: TagChild = None,
25+
target: Optional[str] = None,
26+
position: Literal["after", "before"] = "after",
27+
select: bool = False,
28+
session: Optional[Session] = None,
29+
) -> None:
30+
"""
31+
Create a nav item pointing to some internal content.
32+
33+
Parameters
34+
----------
35+
id
36+
The id of the navset container to insert the item into.
37+
title
38+
A title to display. Can be a character string or UI elements (i.e., tags).
39+
*args
40+
UI elements to display when the item is active.
41+
value
42+
The value of the item. Use this value to determine whether the item is active
43+
(when an `id` is provided to the nav container) or to programmatically
44+
select the item (e.g., :func:`~shiny.ui.update_navs`). You can also
45+
provide the value to the `selected` argument of the navigation container
46+
(e.g., :func:`~shiny.ui.navset_tab`).
47+
icon
48+
An icon to appear inline with the button/link.
49+
target
50+
The `value` of an existing :func:`shiny.ui.nav` item, next to which tab will
51+
be added. Can also be `None`; see `position`.
52+
position
53+
The position of the new nav item relative to the target nav item. If
54+
`target=None`, then `"before"` means the new nav item should be inserted at
55+
the head of the navlist, and `"after"` is the end.
56+
select
57+
Whether the nav item should be selected upon insertion.
58+
session
59+
A :class:`~shiny.Session` instance. If not provided, it is inferred via
60+
:func:`~shiny.session.get_current_session`.
61+
"""
62+
63+
from ...ui import nav_insert, nav_panel
64+
65+
panel = nav_panel(
66+
title,
67+
*args,
68+
value=value,
69+
icon=icon,
70+
)
71+
72+
nav_insert(
73+
id=id,
74+
nav_panel=panel,
75+
target=target,
76+
position=position,
77+
select=select,
78+
session=session,
79+
)

0 commit comments

Comments
 (0)