Skip to content

Commit e1f61bf

Browse files
authored
Remove express.ui.output_* functions, add shiny.express.render (#1018)
1 parent 68a94da commit e1f61bf

File tree

25 files changed

+247
-150
lines changed

25 files changed

+247
-150
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
* Added `@render.download` as a replacement for `@session.download`, which is now deprecated. (#977)
1818

19+
* Added `ui.output_code()`, which is currently an alias for `ui.output_text_verbatim()`. (#997)
20+
21+
* Added `@render.code`, which is an alias for `@render.text`, but in Express mode, it displays the result using `ui.output_code()`. (#997)
22+
1923
### Bug fixes
2024

2125
* CLI command `shiny create`... (#965)

docs/_quartodoc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ quartodoc:
158158
- ui.output_table
159159
- ui.output_data_frame
160160
- ui.output_text
161+
- ui.output_code
161162
- ui.output_text_verbatim
162163
- ui.output_ui
163164
- render.plot

shiny/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""A package for building reactive web applications."""
22

3-
__version__ = "0.6.1.9003"
3+
__version__ = "0.6.1.9004"
44

55
from ._shinyenv import is_pyodide as _is_pyodide
66

shiny/api-examples/Renderer/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class render_capitalize(Renderer[str]):
2828
Whether to render a placeholder value. (Defaults to `True`)
2929
"""
3030

31-
def default_ui(self, id: str):
31+
def auto_output_ui(self, id: str):
3232
"""
3333
Express UI for the renderer
3434
"""
@@ -94,7 +94,7 @@ class render_upper(Renderer[str]):
9494
Note: This renderer is equivalent to `render_capitalize(to="upper")`.
9595
"""
9696

97-
def default_ui(self, id: str):
97+
def auto_output_ui(self, id: str):
9898
"""
9999
Express UI for the renderer
100100
"""

shiny/express/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
# console.
55
from ..session import Inputs as _Inputs, Outputs as _Outputs, Session as _Session
66
from ..session import _utils as _session_utils
7+
from .. import render
78
from . import ui
89
from ._is_express import is_express_app
910
from ._output import ( # noqa: F401
10-
ui_kwargs,
1111
suspend_display,
1212
output_args, # pyright: ignore[reportUnusedImport]
1313
)
1414
from ._run import wrap_express_app
1515
from .display_decorator import display_body
1616

17+
1718
__all__ = (
19+
"render",
1820
"input",
1921
"output",
2022
"session",
2123
"is_express_app",
22-
"ui_kwargs",
2324
"suspend_display",
2425
"wrap_express_app",
2526
"ui",

shiny/express/_output.py

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,16 @@
88
from .. import ui
99
from .._typing_extensions import ParamSpec
1010
from ..render.renderer import RendererBase, RendererBaseT
11-
from ..render.transformer import OutputRenderer
12-
from ..render.transformer._transformer import OT
1311

14-
__all__ = (
15-
"ui_kwargs",
16-
"suspend_display",
17-
)
12+
__all__ = ("suspend_display",)
1813

1914
P = ParamSpec("P")
2015
R = TypeVar("R")
2116
CallableT = TypeVar("CallableT", bound=Callable[..., object])
2217

2318

2419
# TODO-barret-future; quartodoc entry?
25-
def ui_kwargs(
20+
def output_args(
2621
**kwargs: object,
2722
) -> Callable[[RendererBaseT], RendererBaseT]:
2823
"""
@@ -31,9 +26,9 @@ def ui_kwargs(
3126
Each Shiny render function (like :func:`~shiny.render.plot`) can display itself when
3227
declared within a Shiny inline-style application. In the case of
3328
:func:`~shiny.render.plot`, the :func:`~shiny.ui.output_plot` function is called
34-
implicitly to display the plot. Use the `@ui_kwargs` decorator to specify
35-
arguments to be passed to `output_plot` (or whatever the corresponding UI function
36-
is) when the render function displays itself.
29+
implicitly to display the plot. Use the `@ui_kwargs` decorator to specify arguments
30+
to be passed to `output_plot` (or whatever the corresponding UI function is) when
31+
the render function displays itself.
3732
3833
Parameters
3934
----------
@@ -47,51 +42,7 @@ def ui_kwargs(
4742
"""
4843

4944
def wrapper(renderer: RendererBaseT) -> RendererBaseT:
50-
# renderer._default_ui_args = args
51-
renderer._default_ui_kwargs = kwargs
52-
return renderer
53-
54-
return wrapper
55-
56-
57-
def output_args(
58-
*args: object,
59-
**kwargs: object,
60-
) -> Callable[[OutputRenderer[OT]], OutputRenderer[OT]]:
61-
"""
62-
Sets default UI arguments for a Shiny rendering function.
63-
64-
Each Shiny render function (like :func:`~shiny.render.plot`) can display itself when
65-
declared within a Shiny inline-style application. In the case of
66-
:func:`~shiny.render.plot`, the :func:`~shiny.ui.output_plot` function is called
67-
implicitly to display the plot. Use the `@output_args` decorator to specify
68-
arguments to be passed to `output_plot` (or whatever the corresponding UI function
69-
is) when the render function displays itself.
70-
71-
72-
Parameters
73-
----------
74-
*args
75-
Positional arguments to be passed to the UI function.
76-
**kwargs
77-
Keyword arguments to be passed to the UI function.
78-
79-
Returns
80-
-------
81-
:
82-
A decorator that sets the default UI arguments for a Shiny rendering function.
83-
"""
84-
85-
def wrapper(renderer: OutputRenderer[OT]) -> OutputRenderer[OT]:
86-
if not isinstance(renderer, OutputRenderer):
87-
raise TypeError(
88-
f"Expected an OutputRenderer, but got {type(renderer).__name__}."
89-
"\nIf you are trying to set default UI arguments for a `Renderer`, use"
90-
" `@ui_kwargs` instead."
91-
)
92-
renderer._default_ui_args = args
93-
renderer._default_ui_kwargs = kwargs
94-
45+
renderer._auto_output_ui_kwargs = kwargs
9546
return renderer
9647

9748
return wrapper
@@ -152,7 +103,7 @@ def suspend_display(
152103
# display yourself"
153104
if isinstance(fn, RendererBase):
154105
# By setting the class value, the `self` arg will be auto added.
155-
fn.default_ui = null_ui
106+
fn.auto_output_ui = null_ui
156107
return fn
157108

158109
return suspend_display_ctxmgr()(fn)

shiny/express/ui/__init__.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
SliderStepArg,
3939
SliderValueArg,
4040
ValueBoxTheme,
41-
download_button,
42-
download_link,
4341
brush_opts,
4442
click_opts,
4543
dblclick_opts,
@@ -95,14 +93,7 @@
9593
notification_show,
9694
notification_remove,
9795
nav_spacer,
98-
output_plot,
99-
output_image,
100-
output_text,
101-
output_text_verbatim,
102-
output_table,
103-
output_ui,
10496
Progress,
105-
output_data_frame,
10697
value_box_theme,
10798
)
10899

@@ -178,8 +169,6 @@
178169
"SliderStepArg",
179170
"SliderValueArg",
180171
"ValueBoxTheme",
181-
"download_button",
182-
"download_link",
183172
"brush_opts",
184173
"click_opts",
185174
"dblclick_opts",
@@ -235,14 +224,7 @@
235224
"notification_show",
236225
"notification_remove",
237226
"nav_spacer",
238-
"output_plot",
239-
"output_image",
240-
"output_text",
241-
"output_text_verbatim",
242-
"output_table",
243-
"output_ui",
244227
"Progress",
245-
"output_data_frame",
246228
"value_box_theme",
247229
# Imports from ._cm_components
248230
"sidebar",
@@ -301,6 +283,17 @@
301283
"showcase_bottom",
302284
"showcase_left_center",
303285
"showcase_top_right",
286+
# Outputs automatically placed by render functions
287+
"download_button",
288+
"download_link",
289+
"output_plot",
290+
"output_image",
291+
"output_text",
292+
"output_code",
293+
"output_text_verbatim",
294+
"output_table",
295+
"output_ui",
296+
"output_data_frame",
304297
),
305298
# Items from shiny.express.ui that don't have a counterpart in shiny.ui
306299
"shiny.express.ui": ("page_opts",),

shiny/render/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
display,
1616
)
1717
from ._render import (
18+
code,
1819
image,
1920
plot,
2021
table,
@@ -28,6 +29,7 @@
2829
"data_frame",
2930
"display",
3031
"text",
32+
"code",
3133
"plot",
3234
"image",
3335
"table",

shiny/render/_dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class data_frame(Renderer[DataFrameResult]):
256256
objects you can return from the rendering function to specify options.
257257
"""
258258

259-
def default_ui(self, id: str) -> Tag:
259+
def auto_output_ui(self, id: str) -> Tag:
260260
return ui.output_data_frame(id=id)
261261

262262
async def transform(self, value: DataFrameResult) -> Jsonifiable:

shiny/render/_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
class display(Renderer[None]):
21-
def default_ui(
21+
def auto_output_ui(
2222
self,
2323
id: str,
2424
*,

0 commit comments

Comments
 (0)