-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Component
UI (ui.*)
Severity
P3 - Low (minor inconvenience)
Shiny Version
1.4.0
Python Version
3.13.5
Minimal Reproducible Example
from shiny import module, ui
@module.ui
def modui():
return ui.div(id="divid")
print(modui("modid"))Behavior
Current: <div id="divid"></div>
Expected: <div id="modid-divid"></div>
I also want the wrapper's parameter in module.ui named something else than id since the user might want to use id as a parameter for the wrapped function. Something like _moduleid is preferred.
Lines 28 to 61 in d656fdb
| def ui(fn: Callable[P, R]) -> Callable[Concatenate[str, P], R]: | |
| """ | |
| Decorator for defining a Shiny module UI function. | |
| This decorator allows you to write the UI portion of a Shiny module. | |
| When your decorated `ui` function is called with an `id`, | |
| the UI elements defined within will automatically be namespaced using that `id`. | |
| This enables reuse of UI components and consistent input/output handling | |
| when paired with a :func:`shiny.module.server` function. | |
| Parameters | |
| ---------- | |
| fn | |
| A function that returns a Shiny UI element or layout (e.g., a `ui.panel_*` component). | |
| This function should **not** accept an `id` parameter itself; the decorator injects it. | |
| Returns | |
| ------- | |
| : | |
| A function that takes a `str` `id` as its first argument, followed by any additional | |
| parameters accepted by `fn`. When called, it returns UI elements with input/output | |
| IDs automatically namespaced using the provided module `id`. | |
| See Also | |
| -------- | |
| * Shiny Modules documentation: <https://shiny.posit.co/py/docs/modules.html> | |
| * :func:`shiny.module.server` | |
| """ | |
| def wrapper(id: Id, *args: P.args, **kwargs: P.kwargs) -> R: | |
| with namespace_context(id): | |
| return fn(*args, **kwargs) | |
| return wrapper |
Error Messages (if any)
Environment
NAMetadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation