|  | 
|  | 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