Skip to content

Commit b2a60dc

Browse files
docs: Function Reference Proofreads (#919)
Co-authored-by: Garrett Grolemund <[email protected]> Co-authored-by: Garrett Grolemund <[email protected]>
1 parent ec4e7a8 commit b2a60dc

21 files changed

+305
-238
lines changed

docs/_renderer.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from quartodoc.pandoc.blocks import DefinitionList
1717
from quartodoc.renderers.base import convert_rst_link_to_md, sanitize
1818

19+
# from quartodoc.ast import preview
20+
1921
SHINY_PATH = Path(files("shiny").joinpath())
2022

2123
SHINYLIVE_CODE_TEMPLATE = """
@@ -142,9 +144,37 @@ def render_annotation(self, el: exp.ExprName):
142144
return f"[{el.name}](`{el.canonical_path}`)"
143145

144146
@dispatch
145-
def summarize(self, el: dc.Object | dc.Alias):
146-
result = super().summarize(el)
147-
return html.escape(result)
147+
# Overload of `quartodoc.renderers.md_renderer` to fix bug where the descriptions
148+
# are cut off and never display other places. Fixing by always displaying the
149+
# documentation.
150+
def summarize(self, obj: Union[dc.Object, dc.Alias]) -> str:
151+
# get high-level description
152+
doc = obj.docstring
153+
if doc is None:
154+
docstring_parts = []
155+
else:
156+
docstring_parts = doc.parsed
157+
158+
if len(docstring_parts) and isinstance(
159+
docstring_parts[0], ds.DocstringSectionText
160+
):
161+
description = docstring_parts[0].value
162+
163+
# ## Approach: Always return the full description!
164+
return description
165+
166+
# ## Alternative: Add ellipsis if the lines are cut off
167+
168+
# # If the description is more than one line, only show the first line.
169+
# # Add `...` to indicate the description was truncated
170+
# parts = description.split("\n")
171+
# short = parts[0]
172+
# if len(parts) > 1:
173+
# short += "&hellip;"
174+
175+
# return short
176+
177+
return ""
148178

149179
# Consolidate the parameter type info into a single column
150180
@dispatch

shiny/_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class App:
4646
----------
4747
ui
4848
The UI definition for the app (e.g., a call to :func:`~shiny.ui.page_fluid` or
49-
:func:`~shiny.ui.page_fixed`, with layouts and controls nested inside). You can
49+
similar, with layouts and controls nested inside). You can
5050
also pass a function that takes a :class:`~starlette.requests.Request` and
5151
returns a UI definition, if you need the UI definition to be created dynamically
5252
for each pageview.
5353
server
54-
A function which is called once for each session, ensuring that each app is
54+
A function which is called once for each session, ensuring that each session is
5555
independent.
5656
static_assets
5757
Static files to be served by the app. If this is a string or Path object, it

shiny/_main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def run_app(
197197
**kwargs: object,
198198
) -> None:
199199
"""
200-
Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop.
200+
Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop the app.
201201
202202
Parameters
203203
----------
@@ -207,8 +207,8 @@ def run_app(
207207
directory. In other cases, the app location can be specified as a
208208
``<module>:<attribute>`` string where the ``:<attribute>`` is only necessary if
209209
the application is named something other than ``app``. Note that ``<module>``
210-
can be relative path to a ``.py`` file or a directory (with an ``app.py`` file
211-
inside it); and in this case, the relative path is resolved relative to the
210+
can be a relative path to a ``.py`` file or a directory (with an ``app.py`` file
211+
inside of it); and in this case, the relative path is resolved relative to the
212212
``app_dir`` directory.
213213
host
214214
The address that the app should listen on.
@@ -220,8 +220,8 @@ def run_app(
220220
reload
221221
Enable auto-reload.
222222
reload_dirs
223-
List of directories (in addition to the app directory) to watch for changes that
224-
will trigger app reloading.
223+
A list of directories (in addition to the app directory) to watch for changes that
224+
will trigger an app reload.
225225
reload_includes
226226
List or tuple of file globs to indicate which files should be monitored for
227227
changes. Can be combined with `reload_excludes`.
@@ -233,7 +233,7 @@ def run_app(
233233
log_level
234234
Log level.
235235
app_dir
236-
Look for ``app`` under this directory (by adding this to the ``PYTHONPATH``).
236+
The directory to look for ``app`` under (by adding this to the ``PYTHONPATH``).
237237
factory
238238
Treat ``app`` as an application factory, i.e. a () -> <ASGI app> callable.
239239
launch_browser
@@ -245,7 +245,7 @@ def run_app(
245245
Tip
246246
---
247247
The ``shiny run`` command-line interface (which comes installed with Shiny) provides
248-
the same functionality as this function.
248+
the same functionality as :func:`~shiny.run_app`.
249249
250250
Examples
251251
--------

shiny/_validation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def req(*args: T, cancel_output: bool = False) -> T | None:
2626
This is a convenient shorthand for throwing :func:`~shiny.types.SilentException` /
2727
:func:`~shiny.types.SilentCancelOutputException` if any of the arguments are falsy.
2828
29+
The term "falsy" generally indicates that a value is considered `False` when
30+
encountered in a logical context. We use the term a little loosely here; our usage
31+
tries to match the intuitive notions of "Is this value missing or available?", or
32+
"Has the user provided an answer?", or in the case of action buttons, "Has the
33+
button been clicked?". So `False`, `None`, `0`, and `""` would be examples of Falsy
34+
values.
35+
2936
Parameters
3037
----------
3138
*args

shiny/experimental/ui/_card.py

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@ def card(
4848
"""
4949
A Bootstrap card component
5050
51-
A general purpose container for grouping related UI elements together with a border
52-
and optional padding. To learn more about `card()`s, see [this
51+
A card is a general purpose container that groups related UI elements together with a border
52+
and optional padding. To learn more about `card()`s, see [the bslib card
5353
article](https://rstudio.github.io/bslib/articles/cards.html).
5454
5555
Parameters
5656
----------
5757
*args
58-
Unnamed arguments can be any valid child of an :class:`~htmltools.Tag` (which
59-
includes card items such as :func:`~shiny.experimental.ui.card_body`.
58+
Unnamed arguments can be any valid child of an :class:`~htmltools.Tag` (This
59+
includes card items such as :func:`~shiny.experimental.ui.card_body`).
6060
full_screen
61-
If `True`, an icon will appear when hovering over the card body. Clicking the
61+
If `True`, an icon will appear when the user's pointer hovers over the card body. Clicking the
6262
icon expands the card to fit viewport size.
63-
height,max_height,min_height
64-
Any valid CSS unit (e.g., `height="200px"`). Doesn't apply when a card is made
65-
`full_screen` (in this case, consider setting a `height` in
66-
:func:`~shiny.experimental.ui.card_body`).
63+
height, max_height, min_height
64+
Any valid CSS unit (e.g., `height="200px"`). These will not apply when a card is made
65+
`full_screen`. In this case, consider setting a `height` in
66+
:func:`~shiny.experimental.ui.card_body`.
6767
fill
6868
Whether or not to allow the card to grow/shrink to fit a fillable container with
6969
an opinionated height (e.g., :func:`~shiny.ui.page_fillable`).
7070
class_
7171
Additional CSS classes for the returned Tag.
7272
wrapper
73-
A function (which returns a UI element) to call on unnamed arguments in `*args`
74-
which are not already card item(s) (like
73+
A function that returns a UI element to call on any unnamed arguments in `*args`
74+
that are not already card item(s) (like
7575
:func:`~shiny.ui.card_header`,
7676
:func:`~shiny.experimental.ui.card_body`, etc.). Note that non-card items are
7777
grouped together into one `wrapper` call (e.g. given `card("a", "b",
@@ -83,17 +83,17 @@ def card(
8383
Returns
8484
-------
8585
:
86-
An :func:`~shiny.ui.tags.div` tag.
86+
A :func:`~shiny.ui.tags.div` tag.
8787
8888
See Also
8989
--------
9090
* :func:`~shiny.ui.layout_column_wrap` for laying out multiple cards
91-
(or multiple columns inside a card).
92-
* :func:`~shiny.ui.card_header` for creating a header within the card.
93-
* :func:`~shiny.experimental.ui.card_title` for creating a title within the card body.
94-
* :func:`~shiny.experimental.ui.card_body` for putting content inside the card.
95-
* :func:`~shiny.ui.card_footer` for creating a footer within the card.
96-
* :func:`~shiny.experimental.ui.card_image` for adding an image to the card.
91+
or multiple columns inside a card.
92+
* :func:`~shiny.ui.card_header` for creating a header within a card.
93+
* :func:`~shiny.experimental.ui.card_title` for creating a title within a card body.
94+
* :func:`~shiny.experimental.ui.card_body` for putting content inside a card.
95+
* :func:`~shiny.ui.card_footer` for creating a footer within a card.
96+
* :func:`~shiny.experimental.ui.card_image` for adding an image to a card.
9797
"""
9898
return _card_impl(
9999
*args,
@@ -118,33 +118,35 @@ def card_title(
118118
**kwargs: TagAttrValue,
119119
) -> Tagifiable:
120120
"""
121-
Card title container
121+
A card title container
122122
123-
A general container for the "title" of a :func:`~shiny.ui.card`. This component is designed
123+
:func:`~shiny.experimental.ui.card_title` creates a general container for the "title" of
124+
a :func:`~shiny.ui.card`. This component is designed
124125
to be provided as a direct child to :func:`~shiny.ui.card`.
125126
126127
Parameters
127128
----------
128129
*args
129-
Contents to the card's title. Or tag attributes that are supplied to the
130+
Contents to appear in the card's title, or tag attributes to pass to the
130131
resolved :class:`~htmltools.Tag` object.
131132
container
132-
Method for the returned Tag object. Defaults to :func:`shiny.ui.tags.h5`.
133+
Method for the returned :class:`~htmltools.Tag` object. Defaults to
134+
:func:`~shiny.ui.tags`.h5.
133135
**kwargs
134-
Additional HTML attributes for the returned Tag.
136+
Additional HTML attributes for the returned :class:`~htmltools.Tag` object.
135137
136138
Returns
137139
-------
138140
:
139-
A Tag object.
141+
An :class:`~htmltools.Tag` object.
140142
141143
See Also
142144
--------
143145
* :func:`~shiny.ui.card` for creating a card component.
144-
* :func:`~shiny.ui.card_header` for creating a header within the card.
145-
* :func:`~shiny.experimental.ui.card_body` for putting content inside the card.
146-
* :func:`~shiny.ui.card_footer` for creating a footer within the card.
147-
* :func:`~shiny.experimental.ui.card_image` for adding an image to the card.
146+
* :func:`~shiny.ui.card_header` for creating a header within a card.
147+
* :func:`~shiny.experimental.ui.card_body` for putting content inside a card.
148+
* :func:`~shiny.ui.card_footer` for creating a footer within a card.
149+
* :func:`~shiny.experimental.ui.card_image` for adding an image to a card.
148150
"""
149151
return container(*args, **kwargs)
150152

@@ -188,21 +190,22 @@ def card_image(
188190
**kwargs: TagAttrValue,
189191
) -> Tagifiable:
190192
"""
191-
Card image container
193+
A card image container
192194
193-
A general container for an image within a :func:`~shiny.ui.card`. This component is designed to be
195+
:func:`~shiny.experimental.ui.card_image` creates a general container for an image within a
196+
:func:`~shiny.ui.card`. This component is designed to be
194197
provided as a direct child to :func:`~shiny.ui.card`.
195198
196199
Parameters
197200
----------
198201
file
199-
A file path pointing an image. The image will be base64 encoded and provided to
200-
the `src` attribute of the `<img>`. Alternatively, you may set this value to
202+
A file path pointing to an image. The image will be base64 encoded and provided to
203+
the `src` attribute of the `<img>` tag. Alternatively, you may set this value to
201204
`None` and provide the `src` yourself via `*args:TagAttrs` or
202-
`**kwargs:TagAttrValue` (e.g. `{"src": "HOSTED_PATH_TO_IMAGE"}` or
205+
`**kwargs:TagAttrValue` (e.g., `{"src": "HOSTED_PATH_TO_IMAGE"}` or
203206
`src="HOSTED_PATH_TO_IMAGE"`).
204207
*args
205-
Dictionary of tag attributes that are supplied to the resolved
208+
A dictionary of tag attributes that are supplied to the resolved
206209
:class:`~htmltools.Tag` object.
207210
href
208211
An optional URL to link to.
@@ -211,23 +214,24 @@ def card_image(
211214
mime_type
212215
The mime type of the `file`.
213216
class_
214-
Additional CSS classes for the resolved Tag.
217+
Additional CSS classes for the resolved :class:`~htmltools.Tag` object.
215218
height
216-
Any valid CSS unit (e.g., `height="200px"`). Doesn't apply when a card is made
217-
`full_screen` (in this case, consider setting a `height` in
218-
:func:`~shiny.experimental.ui.card_body`).
219+
Any valid CSS unit (e.g., `height="200px"`). `height` will not apply when a card is made
220+
`full_screen`. In this case, consider setting a `height` in
221+
:func:`~shiny.experimental.ui.card_body`.
219222
fill
220223
Whether to allow this element to grow/shrink to fit its `card` container.
221224
width
222225
Any valid CSS unit (e.g., `width="100%"`).
223226
container
224-
Method to wrap the returned Tag object. Defaults to :func:`~shiny.experimental.ui.card_body`.
227+
Method to wrap the returned :class:`~htmltools.Tag` object. Defaults to
228+
:func:`~shiny.experimental.ui.card_body`.
225229
If :func:`~shiny.experimental.ui.card_body` is used, each image will be in separate cards. If
226230
the `container` method does not return a :class:`~shiny.ui.CardItem`, it
227231
allows for consecutive non-`CardItem` objects to be bundled into a single
228232
:func:`~shiny.experimental.ui.card_body` within :func:`~shiny.ui.card`.
229233
**kwargs
230-
Additional HTML attributes for the resolved Tag.
234+
Additional HTML attributes for the resolved :class:`~htmltools.Tag`.
231235
"""
232236
src = None
233237
if file is not None:

0 commit comments

Comments
 (0)