Skip to content

Commit 940ae7d

Browse files
authored
Add docstrings/API reference for UI subpackage (#42)
1 parent 1e552d2 commit 940ae7d

File tree

76 files changed

+4038
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4038
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ ENV/
104104
typings/
105105

106106
docs/source/generated/
107+
docs/source/reference/

docs/source/api.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/source/index.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

docs/source/index.rst

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
Shiny for Python API Reference
2+
================
3+
4+
* :ref:`search`
5+
6+
7+
Page containers
8+
~~~~~~~~~~~~~~~
9+
10+
Create a user interface page container.
11+
12+
.. autosummary::
13+
:toctree: reference/
14+
15+
~shiny.ui.page_navbar
16+
~shiny.ui.page_fluid
17+
~shiny.ui.page_fixed
18+
~shiny.ui.page_bootstrap
19+
20+
21+
UI Layout
22+
~~~~~~~~~
23+
24+
Control the layout of multiple UI components.
25+
26+
.. autosummary::
27+
:toctree: reference/
28+
29+
~shiny.ui.layout_sidebar
30+
~shiny.ui.panel_sidebar
31+
~shiny.ui.panel_main
32+
~shiny.ui.column
33+
~shiny.ui.row
34+
35+
UI Inputs
36+
~~~~~~~~~
37+
38+
Create UI that prompts the user for input values or interaction.
39+
40+
.. autosummary::
41+
:toctree: reference/
42+
43+
~shiny.ui.input_select
44+
~shiny.ui.input_selectize
45+
~shiny.ui.input_slider
46+
~shiny.ui.input_date
47+
~shiny.ui.input_date_range
48+
~shiny.ui.input_checkbox
49+
~shiny.ui.input_checkbox_group
50+
~shiny.ui.input_radio_buttons
51+
~shiny.ui.input_numeric
52+
~shiny.ui.input_text
53+
~shiny.ui.input_text_area
54+
~shiny.ui.input_password
55+
~shiny.ui.input_action_button
56+
57+
58+
Update inputs
59+
~~~~~~~~~~~~~
60+
61+
Programmatically update input values
62+
63+
.. autosummary::
64+
:toctree: reference/
65+
66+
~shiny.ui.update_select
67+
~shiny.ui.update_slider
68+
~shiny.ui.update_date
69+
~shiny.ui.update_date_range
70+
~shiny.ui.update_checkbox
71+
~shiny.ui.update_checkbox_group
72+
~shiny.ui.update_radio_buttons
73+
~shiny.ui.update_numeric
74+
~shiny.ui.update_text
75+
~shiny.ui.update_text_area
76+
~shiny.ui.update_navs
77+
78+
79+
Navigation (tab) panels
80+
~~~~~~~~~~~~~~~~~~~~~~~
81+
82+
Create segments of UI content.
83+
84+
.. autosummary::
85+
:toctree: reference/
86+
87+
~shiny.ui.nav
88+
~shiny.ui.nav_item
89+
~shiny.ui.nav_spacer
90+
~shiny.ui.nav_menu
91+
~shiny.ui.navs_tab
92+
~shiny.ui.navs_tab_card
93+
~shiny.ui.navs_pill
94+
~shiny.ui.navs_pill_card
95+
~shiny.ui.navs_pill_list
96+
97+
98+
UI panels
99+
~~~~~~~~~
100+
101+
Visually group together a section of UI components.
102+
103+
.. autosummary::
104+
:toctree: reference/
105+
106+
~shiny.ui.panel_absolute
107+
~shiny.ui.panel_fixed
108+
~shiny.ui.panel_conditional
109+
~shiny.ui.panel_title
110+
~shiny.ui.panel_well
111+
112+
113+
Uploads & downloads
114+
~~~~~~~~~~~~~~~~~~~
115+
116+
Allows users to upload and download files.
117+
118+
.. autosummary::
119+
:toctree: reference/
120+
121+
~shiny.ui.input_file
122+
~shiny.ui.download_button
123+
124+
125+
Custom UI
126+
~~~~~~~~~~
127+
128+
Lower-level UI functions for creating custom HTML/CSS/JS.
129+
130+
.. autosummary::
131+
:toctree: reference/
132+
133+
~shiny.ui.HTML
134+
~shiny.ui.tags
135+
~shiny.ui.TagList
136+
~shiny.ui.insert_ui
137+
~shiny.ui.remove_ui
138+
139+
140+
Rendering outputs
141+
~~~~~~~~~~~~~~~~~~
142+
143+
UI (`output_*()`) and server (``render_*()``) functions for generating content server-side.
144+
145+
.. autosummary::
146+
:toctree: reference/
147+
148+
~shiny.ui.output_plot
149+
~shiny.render_plot
150+
~shiny.ui.output_image
151+
~shiny.render_image
152+
~shiny.ui.output_text
153+
~shiny.ui.output_text_verbatim
154+
~shiny.render_text
155+
~shiny.ui.output_ui
156+
~shiny.render_ui
157+
158+
159+
Reactive programming
160+
~~~~~~~~~~~~~~~~~~
161+
162+
Reactive programming facilities for Python.
163+
164+
.. autosummary::
165+
:toctree: reference/
166+
167+
~shiny.reactive.Calc
168+
~shiny.reactive.Effect
169+
~shiny.reactive.Value
170+
~shiny.reactive.isolate
171+
~shiny.reactive.invalidate_later
172+
~shiny.reactive.flush
173+
~shiny.event
174+
175+
176+
Create and run applications
177+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
178+
179+
Create, run, stop, and hook into the lifecycle of Shiny applications.
180+
181+
.. autosummary::
182+
:toctree: reference/
183+
184+
~shiny.App
185+
~shiny.run_app
186+
~shiny.Inputs
187+
~shiny.Outputs
188+
~shiny.Session
189+
190+
Display messages
191+
~~~~~~~~~~~~~~~~
192+
193+
Display messages to the user.
194+
195+
.. autosummary::
196+
:toctree: reference/
197+
198+
~shiny.ui.help_text
199+
~shiny.ui.notification_show
200+
~shiny.ui.notification_remove
201+
~shiny.ui.Progress
202+
~shiny.ui.modal
203+
~shiny.ui.modal_show
204+
~shiny.ui.modal_remove
205+
~shiny.ui.modal_button
206+
207+
Error validation
208+
~~~~~~~~~~~~~~~~
209+
210+
Control how errors are shown to the user.
211+
212+
.. autosummary::
213+
:toctree: reference/
214+
215+
~shiny.req
216+
~shiny.types.SilentException
217+
~shiny.types.SilentCancelOutputException
218+
~shiny.types.SafeException
219+
220+
221+
Modules
222+
~~~~~~~
223+
224+
Control application complexity by namespacing UI and server code.
225+
226+
.. autosummary::
227+
:toctree: reference/
228+
229+
~shiny.modules.Module
230+
~shiny.modules.ModuleInputs
231+
~shiny.modules.ModuleOutputs
232+
~shiny.modules.ModuleSession

examples/inputs/rstudio-logo.png

-140 KB
Loading

shiny/_docstring.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
from typing import Callable, Any, TypeVar
3+
4+
ex_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "examples")
5+
6+
FuncType = Callable[..., Any]
7+
F = TypeVar("F", bound=FuncType)
8+
9+
10+
def add_example() -> Callable[[F], F]:
11+
def _(func: F) -> F:
12+
fn_name = func.__name__
13+
example_file = os.path.join(ex_dir, fn_name, "app.py")
14+
if not os.path.exists(example_file):
15+
raise ValueError(f"No example for {fn_name}")
16+
17+
with open(example_file) as f:
18+
example = [" " * 8 + x for x in f.readlines()]
19+
example = "".join(example)
20+
21+
if func.__doc__ is None:
22+
func.__doc__ = ""
23+
24+
func.__doc__ += (
25+
f"\n\n Examples\n --------\n\n .. code-block:: python\n\n{example}"
26+
)
27+
28+
return func
29+
30+
return _
31+
32+
33+
def doc_format(**kwargs: str) -> Callable[[F], F]:
34+
def _(func: F) -> F:
35+
if func.__doc__:
36+
func.__doc__ = func.__doc__.format(**kwargs)
37+
return func
38+
39+
return _

shiny/examples/Progress/app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from shiny import *
2+
3+
app_ui = ui.page_fluid(
4+
ui.output_text("compute"),
5+
ui.input_action_button("button", "Compute"),
6+
)
7+
8+
9+
def server(input: Inputs, output: Outputs, session: Session):
10+
@output()
11+
@render_text()
12+
def compute():
13+
p = ui.Progress(min=1, max=15)
14+
p.set(message="Calculation in progress", detail="This may take a while...")
15+
16+
import time
17+
18+
for i in range(1, 15):
19+
p.set(i, message="Computing")
20+
time.sleep(0.1)
21+
22+
p.close()
23+
24+
return "Done computing!"
25+
26+
27+
app = App(app_ui, server)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
from shiny import *
3+
4+
app_ui = ui.page_fluid(
5+
ui.download_button("downloadData", "Download"),
6+
)
7+
8+
# For more examples of different types of download handlers, see:
9+
# https://github.com/rstudio/prism/blob/68ffc27/examples/download/app.py#L90
10+
def server(input: Inputs, output: Outputs, session: Session):
11+
@session.download()
12+
def downloadData():
13+
return os.path.join(os.path.dirname(__file__), "mtcars.csv")
14+
15+
16+
app = App(app_ui, server)

0 commit comments

Comments
 (0)