shiny.output_maidr
widget.shiny.output_maidr(id, *, width='100%', height='auto', fill=True)Create a container for a :class:render_maidr output.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| id | str | Output id, matching the name of the @render_maidr function. Module namespacing is applied by Shiny, so the same id works inside a :func:shiny.module.ui. |
required |
| width | (str, float or None) | CSS width of the container; a number is pixels, None none. Never wider than the container it is placed in. |
"100%" |
| height | (str, float or None) | CSS height of the container; a number is pixels, None none, which is "auto". With "auto" the output is as tall as the chart, which is as wide as the output up to its own width and shrinks with a narrower one, keeping its shape. With a height of its own, the chart is fitted inside it. |
"auto" |
| fill | bool | Whether the output grows and shrinks to fill a fillable container – a :func:shiny.ui.card, :func:shiny.ui.page_fillable – as :func:shiny.ui.output_plot does by default; the chart is then fitted to the space it is given, and follows it when the card is taken full screen or the window resized. |
True |
Returns
| Name | Type | Description |
|---|---|---|
htmltools.Tag |
The output container. |
Notes
A matplotlib, seaborn or plotnine chart is fitted to an output with a height of its own as object-fit: contain fits an image: scaled, up or down, to the largest size that fits keeping its shape, and centred, with a line kept below it for maidr’s text. The output scrolls to what does not fit – the braille and review fields, a long text – rather than cutting it off. Unlike :func:shiny.render.plot, the figure is not drawn again at the output’s size: the chart drawn once is scaled, so its text grows and shrinks with it; a figure sized near the output keeps its text near its own size. A Plotly, Bokeh or Altair chart is as wide as the output, or its own fixed width, which the output then scrolls to. A Plotly figure with no height of its own, a Bokeh plot stretched or scaled to its container’s height, and an Altair chart of height="container" are as tall as an output with a height of its own less the line for maidr’s text, and 450px in one with none; any other keeps its own height. While one of maidr’s dialogs is open, none of this applies: the output and the box round the chart are set aside, and the chart’s frame is laid out as a notebook’s is, as tall as the window, or the box that scrolls it or cuts what it holds, and scrolled to its middle, so that the dialog is shown whole; over a chart taller than that, the dialog is put where the chart meets the window, which scrolls only as far as it takes to show it. Once the dialog closes the chart is fitted again and the page left where it is, unless none of the chart shows, which is then scrolled into view, below a header fixed at the window’s top.
The container keeps a box of its own once a chart is in it. Shiny’s stylesheet makes a UI output a pass-through container as soon as it has children (display: contents), which took its width and height away with its box; the container’s own display overrides that.
No :class:htmltools.HTMLDependency is attached here, which is the one place this deviates from Shiny’s packaged-component recipe. Whether a chart needs the bundled maidr.js is a per-render decision – use_cdn chooses between the CDN and the bundled copy – so the dependency that serves it rides on the rendered value, where Shiny’s _process_ui registers it, and only when the chart names it (see :meth:render_maidr._bundle_for). Attaching it to the container instead would register the bundle with every app even when every chart on it loads from the CDN.
Examples
>>> from shiny import ui
>>> from maidr.widget.shiny import output_maidr
>>> app_ui = ui.page_fluid(output_maidr("my_plot"))