Skip to content

Commit 9ce7309

Browse files
committed
docs: update module server and ui to incorporate #705
1 parent e58e9f6 commit 9ce7309

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

shiny/module.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,23 @@ def ui(fn: Callable[P, R]) -> Callable[Concatenate[str, P], R]:
2929
"""
3030
Decorator for defining a Shiny module UI function.
3131
32-
This decorator allows you to write the UI portion of a Shiny module.
33-
When your decorated `ui` function is called with an `id`,
34-
the UI elements defined within will automatically be namespaced using that `id`.
32+
A Shiny module is a reusable component that can be embedded within Shiny apps or
33+
other Shiny modules. Each module consists of a UI function and a server function.
34+
Use this decorator to mark the UI function for a module.
35+
36+
The UI function can take whatever parameters are required to create the UI; for
37+
example, a label or a default value. It can also take no parameters, if none are
38+
required.
39+
40+
Whatever parameters the UI function takes, the `ui` decorator will prepend the
41+
signature with a new `id` argument. This argument will be an id string passed by the
42+
caller, that uniquely identifies the module instance within the calling scope.
43+
44+
When the decorated function is called, any Shiny input or output elements created
45+
within the function will automatically have their `id` values prefixed with the
46+
module instance's `id`. This ensures that the input and output elements are uniquely
47+
namespaced and won't conflict with other elements in the same app.
48+
3549
This enables reuse of UI components and consistent input/output handling
3650
when paired with a :func:`shiny.module.server` function.
3751
@@ -44,8 +58,9 @@ def ui(fn: Callable[P, R]) -> Callable[Concatenate[str, P], R]:
4458
Returns
4559
-------
4660
:
47-
A function that takes a `str` `id` as its first argument, followed by any additional
48-
parameters accepted by `fn`. When called, it returns UI elements with input/output
61+
The decorated UI function. The function takes a `str` `id` as its first argument,
62+
followed by any additional parameters accepted by `fn`.
63+
When called, it returns UI elements with input/output
4964
IDs automatically namespaced using the provided module `id`.
5065
5166
See Also
@@ -68,6 +83,21 @@ def server(
6883
"""
6984
Decorator for defining a Shiny module server function.
7085
86+
A Shiny module is a reusable component that can be embedded within Shiny apps or
87+
other Shiny modules. Each module consists of a UI function and a server function.
88+
This decorator is used to encapsulate the server logic for a Shiny module.
89+
90+
Every Shiny module server function must always begin with the same three arguments:
91+
`input`, `output`, and `session`, just like a Shiny app's server function.
92+
93+
After `input`, `output`, and `session`, the server function may include additional
94+
parameters to be used in the server logic; for example, reactive data sources or
95+
file paths that need to be provided by the caller.
96+
97+
This decorator modifies the signature of the decorated server function. The `input`,
98+
`output`, and `session` parameters are removed, and a new `id` parameter is
99+
prepended to the signature.
100+
71101
This decorator is used to encapsulate the server logic for a Shiny module.
72102
It automatically creates a namespaced child `Session` using the provided module `id`,
73103
and passes the appropriate `input`, `output`, and `session` objects to your server function.
@@ -84,9 +114,13 @@ def server(
84114
Returns
85115
-------
86116
:
117+
The decorated server function.
87118
A function that takes a module `id` (as a string) as its first argument,
88119
followed by any arguments expected by `fn`. When called, it will register
89120
the module's server logic in a namespaced context.
121+
The function signature of `fn` will have been
122+
modified to remove `input`, `output`, and `session`, and to prepend a new `id`
123+
parameter.
90124
91125
See Also
92126
--------

0 commit comments

Comments
 (0)