shiny.render.plot#

shiny.render.plot(fn: Union[Callable[[], object], Callable[[], Awaitable[object]]]) shiny.render._render.RenderPlot#
shiny.render.plot(*, alt: Optional[str] = 'None', **kwargs: Any) Callable[[Union[Callable[[], object], Callable[[], Awaitable[object]]]], shiny.render._render.RenderPlot]

Reactively render a plot object as an HTML image.

Parameters
  • alt (Optional[str]) – Alternative text for the image if it cannot be displayed or viewed (i.e., the user uses a screen reader).

  • **kwargs – Additional keyword arguments passed to the relevant method for saving the image (e.g., for matplotlib, arguments to savefig(); for PIL and plotnine, arguments to save()).

Return type

Union[RenderPlot, Callable[[Union[Callable[[], object], Callable[[], Awaitable[object]]]], RenderPlot]]

Returns

  • A decorator for a function that returns any of the following

    1. A matplotlib.figure.Figure instance.

    2. An matplotlib.artist.Artist instance.

    3. A list/tuple of Figure/Artist instances.

    4. An object with a ‘figure’ attribute pointing to a matplotlib.figure.Figure instance.

    5. A PIL.Image.Image instance.

  • It’s also possible to use the matplotlib.pyplot interface; in that case, your

  • function should just call pyplot functions and not return anything. (Note that if

  • the decorated function is async, then it’s not safe to use pyplot. Shiny will detect

  • this case and throw an error asking you to use matplotlib’s object-oriented

  • interface instead.)

Tip

This decorator should be applied before the @output decorator. Also, the name of the decorated function (or @output(id=...)) should match the id of a output_plot() container (see output_plot() for example usage).

See also

output_plot, image