shiny.render_maidr

widget.shiny.render_maidr(
    self
    _fn=None
    *
    width='100%'
    height='auto'
    use_cdn=None
)

Render a plot as an accessible MAIDR chart in a Shiny app.

Decorate a function that returns a plot, and pair it with :func:output_maidr in the UI. The chart is sonified, navigable by keyboard, and readable as braille and text.

Parameters

Name Type Description Default
_fn callable The decorated function. Supplied by Python when the decorator is used bare; None when it is called with options. None
width str CSS width of the output container. "100%"
height str CSS height of the output container. "auto"
use_cdn bool, {"auto"}, or None Where the chart loads maidr.js from – see :func:maidr.render. None defers to the process-wide default. Prefer this argument over :func:maidr.set_use_cdn in a Shiny app: the setter is process-wide state shared by every concurrent session, while this is scoped to one output. None

Returns

Name Type Description
render_maidr The renderer, registered as a Shiny output.

Notes

The decorated function may return a matplotlib or seaborn artist, a Plotly Figure, or an Altair chart. Returning None renders nothing, which is the documented way to leave an output blank.

Any pyplot figure the function opens is closed once the chart has been rendered; see :func:_close_new_figures.

Examples

>>> import matplotlib.pyplot as plt
>>> from shiny import App, ui
>>> from maidr.widget.shiny import output_maidr, render_maidr
>>>
>>> app_ui = ui.page_fluid(output_maidr("bars"))
>>>
>>> def server(input, output, session):
...     @render_maidr
...     def bars():
...         fig, ax = plt.subplots()
...         ax.bar(["a", "b"], [1, 2])
...         return ax
>>>
>>> app = App(app_ui, server)

Methods

Name Description
auto_output_ui Return the container Shiny Express places for this output.
render Run the decorated function and return its chart as Shiny UI.

auto_output_ui

widget.shiny.render_maidr.auto_output_ui(**kwargs)

Return the container Shiny Express places for this output.

Parameters

Name Type Description Default
**kwargs Any Arguments for :func:output_maidr, supplied by :func:shiny.express.output_args and taking precedence over the ones given to the decorator. Shiny splats @output_args(...) into this method, so a renderer whose signature takes nothing raises TypeError there – shiny.render.plot accepts **kwargs here for the same reason. {}

Returns

Name Type Description
htmltools.Tag The output container.

render

widget.shiny.render_maidr.render()

Run the decorated function and return its chart as Shiny UI.

Implemented instead of transform() because the pyplot figures to clean up afterwards can only be told apart from the app’s own by what was open before the function ran. :class:shiny.render.plot overrides render() for the same reason.

Returns

Name Type Description
Jsonifiable or None Shiny’s rendered-UI payload, or None when the decorated function returned None.