as_widget
as_widget function
Coerce an object into an ipywidgets.Widget.
Usage Source
as_widget(x: object)If x is already a Widget, it is returned as-is. Otherwise, the object is coerced based on the package it comes from:
- altair
Chart->altair.JupyterChart - bokeh model (e.g.,
bokeh.plotting.figure) ->jupyter_bokeh.BokehModel - holoviews/hvplot/geoviews object -> bokeh model (via panel)
- ipyvolume
Container(e.g., the return value ofipv.quickscatter()) -> itsipyvolume.Figure - jupyter-scatter
Scatter->jscatter.widget.JupyterScatter - leafmap’s folium and deck backends raise a
TypeError(leafmap’s other backends are already ipywidgets) - lonboard layer ->
lonboard.Map - maplibre
Map->maplibre.ipywidget.MapWidget - matplotlib
FigureorAxes(or a seaborn figure-level grid) ->ipympl.backend_nbagg.Canvas - panel pane/viewable -> bokeh model
- perspective
Table->perspective.widget.PerspectiveWidget - pyobsplot
Obsplot/Plotcreators raise aTypeError(they create charts when called; the result is already an ipywidget) - plotly
Figure->plotly.graph_objects.FigureWidget - reactable
Reactable->reactable.widgets.ReactableWidget - plotnine
ggplot(or plot composition) ->ipympl.backend_nbagg.Canvas - pydeck
Deck->pydeck.widget.DeckGLWidget(pydeck <= 0.8 only; pydeck v0.9 removed its widget, so this raises aTypeErrorthat points to alternatives) - rerun
rerun.notebook.Viewer-> its innerrerun_notebook.Viewerwidget - pyvista
Plotter-> a self-contained client-side (vtk.js) widget (via pyvista’sjupyter_backend='html'export)
Parameters
x : object-
The object to coerce.
Returns
: Widget-
An
ipywidgets.Widget.
Raises
: TypeError-
If
xcan’t be coerced into aWidget(the error message points to shiny’s@render.uidecorator as a fallback for objects with an HTML repr).