gradio.render_maidr

widget.gradio.render_maidr(plot, *, use_cdn=None)

Return the markup of an accessible chart, for a gr.HTML component.

Use it as the component’s value, or return it from an event handler whose output is one.

Parameters

Name Type Description Default
plot Any The chart – a matplotlib or seaborn artist, a Plotly Figure, a Bokeh figure or layout, an Altair chart, or a chart a py-maidr reader returned, such as :func:maidr.read_wandb_history’s. Required: Gradio runs event handlers on separate threads, so matplotlib’s current figure may be another user’s by the time it would be read. required
use_cdn bool, {"auto"}, or None Where the chart loads maidr.js from; see :func:maidr.render. False puts the script, about 2 MB, inside every chart, so an app without network access still works. None defers to :func:maidr.get_use_cdn. Prefer this argument to :func:maidr.set_use_cdn, which changes what every user’s handler renders. None

Returns

Name Type Description
str An <iframe> element whose srcdoc is the chart.

Raises

Name Type Description
TypeError If plot is None.

Examples

>>> import gradio as gr
>>> import matplotlib.pyplot as plt
>>> from maidr.widget.gradio import render_maidr
>>>
>>> def bars(n):
...     fig, ax = plt.subplots()
...     ax.bar(range(n), range(1, n + 1))
...     return render_maidr(ax)
>>>
>>> with gr.Blocks() as demo:
...     n = gr.Slider(2, 10, value=4, step=1, label="Bars")
...     chart = gr.HTML(bars(4))
...     n.change(bars, n, chart)