|
| 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 insert_nav_panel( |
| 20 | + id: str, |
| 21 | + title: TagChild, |
| 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 new nav panel in an existing navset. |
| 32 | +
|
| 33 | + Parameters |
| 34 | + ---------- |
| 35 | + id |
| 36 | + The id of the navset container to insert into. |
| 37 | + title |
| 38 | + A title for the inserted nav panel. Can be a character string or UI elements (i.e., tags). |
| 39 | + *args |
| 40 | + UI elements for the inserted nav panel. |
| 41 | + value |
| 42 | + The value of the panel. Use this value to determine whether the panel 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 title. |
| 49 | + target |
| 50 | + The `value` of an existing :func:`shiny.ui.nav_panel`, next to which tab will |
| 51 | + be added. Can also be `None`; see `position`. |
| 52 | + position |
| 53 | + The position of the new nav panel relative to the target. If |
| 54 | + `target=None`, then `"before"` means the new panel should be inserted at |
| 55 | + the head of the navlist, and `"after"` is the end. |
| 56 | + select |
| 57 | + Whether the nav panel 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 | + Note |
| 63 | + ---- |
| 64 | + Unlike :func:`~shiny.ui.insert_nav_panel`, this function does not support inserting |
| 65 | + of a heading/divider into an existing :func:`~shiny.ui.nav_menu`. To do so, use |
| 66 | + :func:`~shiny.ui.insert_nav_panel` instead of this Express variant (i.e., |
| 67 | + `shiny.ui.insert_nav_panel("id", "Header")`). |
| 68 | + """ |
| 69 | + |
| 70 | + from ...ui import insert_nav_panel, nav_panel |
| 71 | + |
| 72 | + panel = nav_panel( |
| 73 | + title, |
| 74 | + *args, |
| 75 | + value=value, |
| 76 | + icon=icon, |
| 77 | + ) |
| 78 | + |
| 79 | + insert_nav_panel( |
| 80 | + id=id, |
| 81 | + nav_panel=panel, |
| 82 | + target=target, |
| 83 | + position=position, |
| 84 | + select=select, |
| 85 | + session=session, |
| 86 | + ) |
0 commit comments