streamlit.maidr_html
widget.streamlit.maidr_html(plot=None, *, use_cdn=None, _stacklevel=3)Return an accessible chart as a self-contained HTML string.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| plot | Any | The plot to render – a matplotlib or seaborn artist, a Plotly Figure, or an Altair chart. None uses the current matplotlib figure, and warns: that figure is process-global, and Streamlit runs sessions on separate threads, so by the time it is rendered it may be another session’s. Pass the plot explicitly. |
None |
| use_cdn | bool, {"auto"}, or None | Where the chart loads maidr.js from; see :func:maidr.render. None defers to the process-wide default. |
None |
| _stacklevel | int | Internal. Frames to skip when warning, so a warning points at the caller’s own line; :func:render_maidr raises it by one because it sits a frame further out. Not part of the public API – the underscore is the only thing stopping an IDE from offering it. |
3 |
Returns
| Name | Type | Description |
|---|---|---|
| str | A complete HTML fragment, safe to embed in an iframe. |
Notes
Exists as its own entry point so the string can be cached, which is the useful lever against Streamlit rerunning the whole script on every widget interaction::
@st.cache_data
def chart_html(_fig, key):
return maidr_html(_fig)
html = chart_html(fig, key=selected_day)
Both arguments are load-bearing. The underscore on _fig tells Streamlit not to hash it, which a matplotlib Figure does not support – and key is then the only thing left to hash. Without it every argument is skipped, the cache key is constant, and the first chart is returned for the rest of the session: a chart that silently stops matching its own controls.
Under use_cdn=False the ~1.9 MB bundle is embedded in the string. Serialising to HTML is what makes an embed possible at all, and it drops :class:htmltools.HTMLDependency children on the way, so a reference to the bundle would not survive; the source itself has to.