shiny.render_maidr
widget.shiny.render_maidr(
self
_fn=None
*
width='100%'
height='auto'
fill=True
use_cdn=None
hover_mode=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, float or None) | CSS width of the box the chart is fitted to, at the top left of its output, as :func:shiny.render.plot’s width is the image’s; a number is pixels. Never wider than the output. "100%" or None leaves the box the output’s width. |
"100%" |
| height | (str, float or None) | CSS height of that box, likewise: @render_maidr(height=300) gives a 300 pixel box at the top of the output, as @render.plot(height=300) gives a 300 pixel image, in a fillable card too. "auto" or None leaves the box the output’s height: the chart’s own, or the output’s when it has one. |
"auto" |
| fill | bool | Under Shiny Express, whether the output Express places fills a fillable container; see :func:output_maidr. An app that places :func:output_maidr itself gives it there. |
True |
| 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. The bundled copy – what False loads, and what "auto" falls back to offline – is served by the app itself, once per app and version, rather than carried inside every chart. |
None |
| hover_mode | ('pointermove', 'click', 'off') | The chart’s starting value for the reader’s Hover Mode setting; see :func:maidr.render. None leaves maidr.js’s default. |
"pointermove" |
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, a Bokeh figure or layout, 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.
The chart is drawn once, at its figure’s size, and scaled to its box (see :func:output_maidr), so @render_maidr(width=500, height=300) gives a 500 by 300 pixel box, like @render.plot(width=500, height=300), with the chart fitted inside it rather than drawn again at that size. Under Shiny Express as in an app that places :func:output_maidr itself: the output Express places takes only fill from the renderer, and sizes from @output_args.
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. |