Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shiny/api-examples/Renderer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class render_capitalize(Renderer[str]):
Whether to render a placeholder value. (Defaults to `True`)
"""

def default_ui(self, id: str):
def auto_output_ui(self, id: str):
"""
Express UI for the renderer
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ class render_upper(Renderer[str]):
Note: This renderer is equivalent to `render_capitalize(to="upper")`.
"""

def default_ui(self, id: str):
def auto_output_ui(self, id: str):
"""
Express UI for the renderer
"""
Expand Down
5 changes: 3 additions & 2 deletions shiny/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
# console.
from ..session import Inputs as _Inputs, Outputs as _Outputs, Session as _Session
from ..session import _utils as _session_utils
from .. import render
from . import ui
from ._is_express import is_express_app
from ._output import ( # noqa: F401
ui_kwargs,
suspend_display,
output_args, # pyright: ignore[reportUnusedImport]
)
from ._run import wrap_express_app
from .display_decorator import display_body


__all__ = (
"render",
"input",
"output",
"session",
"is_express_app",
"ui_kwargs",
"suspend_display",
"wrap_express_app",
"ui",
Expand Down
70 changes: 9 additions & 61 deletions shiny/express/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,29 @@
from typing import Callable, Generator, TypeVar, overload

from .. import ui
from .._deprecated import warn_deprecated
from .._typing_extensions import ParamSpec
from ..render.renderer import RendererBase, RendererBaseT
from ..render.transformer import OutputRenderer
from ..render.transformer._transformer import OT

__all__ = (
"ui_kwargs",
"suspend_display",
)
__all__ = ("suspend_display",)

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


# TODO-barret-future; quartodoc entry?
def ui_kwargs(
**kwargs: object,
) -> Callable[[RendererBaseT], RendererBaseT]:
"""
Sets default UI arguments for a Shiny rendering function.

Each Shiny render function (like :func:`~shiny.render.plot`) can display itself when
declared within a Shiny inline-style application. In the case of
:func:`~shiny.render.plot`, the :func:`~shiny.ui.output_plot` function is called
implicitly to display the plot. Use the `@ui_kwargs` decorator to specify
arguments to be passed to `output_plot` (or whatever the corresponding UI function
is) when the render function displays itself.

Parameters
----------
**kwargs
Keyword arguments to be passed to the UI function.

Returns
-------
:
A decorator that sets the default UI arguments for a Shiny rendering function.
"""

def wrapper(renderer: RendererBaseT) -> RendererBaseT:
# renderer._default_ui_args = args
renderer._default_ui_kwargs = kwargs
return renderer

return wrapper


def output_args(
*args: object,
**kwargs: object,
) -> Callable[[OutputRenderer[OT]], OutputRenderer[OT]]:
"""
Sets default UI arguments for a Shiny rendering function.

Each Shiny render function (like :func:`~shiny.render.plot`) can display itself when
declared within a Shiny inline-style application. In the case of
:func:`~shiny.render.plot`, the :func:`~shiny.ui.output_plot` function is called
implicitly to display the plot. Use the `@output_args` decorator to specify
arguments to be passed to `output_plot` (or whatever the corresponding UI function
is) when the render function displays itself.


Parameters
----------
*args
Positional arguments to be passed to the UI function.
**kwargs
Keyword arguments to be passed to the UI function.

Returns
-------
:
A decorator that sets the default UI arguments for a Shiny rendering function.
Deprecated. Sets default UI arguments for a Shiny rendering function.
"""
warn_deprecated(
"`shiny.express.output_args()` is deprecated and will be removed in a future version of shiny."
)

def wrapper(renderer: OutputRenderer[OT]) -> OutputRenderer[OT]:
if not isinstance(renderer, OutputRenderer):
Expand All @@ -89,8 +37,8 @@ def wrapper(renderer: OutputRenderer[OT]) -> OutputRenderer[OT]:
"\nIf you are trying to set default UI arguments for a `Renderer`, use"
" `@ui_kwargs` instead."
)
renderer._default_ui_args = args
renderer._default_ui_kwargs = kwargs
renderer._auto_output_ui_args = args
renderer._auto_output_ui_kwargs = kwargs

return renderer

Expand Down Expand Up @@ -152,7 +100,7 @@ def suspend_display(
# display yourself"
if isinstance(fn, RendererBase):
# By setting the class value, the `self` arg will be auto added.
fn.default_ui = null_ui
fn.auto_output_ui = null_ui
return fn

return suspend_display_ctxmgr()(fn)
Expand Down
29 changes: 11 additions & 18 deletions shiny/express/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
SliderStepArg,
SliderValueArg,
ValueBoxTheme,
download_button,
download_link,
brush_opts,
click_opts,
dblclick_opts,
Expand Down Expand Up @@ -95,14 +93,7 @@
notification_show,
notification_remove,
nav_spacer,
output_plot,
output_image,
output_text,
output_text_verbatim,
output_table,
output_ui,
Progress,
output_data_frame,
value_box_theme,
)

Expand Down Expand Up @@ -178,8 +169,6 @@
"SliderStepArg",
"SliderValueArg",
"ValueBoxTheme",
"download_button",
"download_link",
"brush_opts",
"click_opts",
"dblclick_opts",
Expand Down Expand Up @@ -235,14 +224,7 @@
"notification_show",
"notification_remove",
"nav_spacer",
"output_plot",
"output_image",
"output_text",
"output_text_verbatim",
"output_table",
"output_ui",
"Progress",
"output_data_frame",
"value_box_theme",
# Imports from ._cm_components
"sidebar",
Expand Down Expand Up @@ -301,6 +283,17 @@
"showcase_bottom",
"showcase_left_center",
"showcase_top_right",
# Outputs automatically placed by render functions
"download_button",
"download_link",
"output_plot",
"output_image",
"output_text",
"output_code",
"output_text_verbatim",
"output_table",
"output_ui",
"output_data_frame",
),
# Items from shiny.express.ui that don't have a counterpart in shiny.ui
"shiny.express.ui": ("page_opts",),
Expand Down
2 changes: 1 addition & 1 deletion shiny/render/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class data_frame(Renderer[DataFrameResult]):
objects you can return from the rendering function to specify options.
"""

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

async def transform(self, value: DataFrameResult) -> Jsonifiable:
Expand Down
2 changes: 1 addition & 1 deletion shiny/render/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class display(Renderer[None]):
def default_ui(
def auto_output_ui(
self,
id: str,
*,
Expand Down
Loading