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 of ipv.quickscatter()) -> its ipyvolume.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 Figure or Axes (or a seaborn figure-level grid) -> ipympl.backend_nbagg.Canvas
  • panel pane/viewable -> bokeh model
  • perspective Table -> perspective.widget.PerspectiveWidget
  • pyobsplot Obsplot/Plot creators raise a TypeError (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 a TypeError that points to alternatives)
  • rerun rerun.notebook.Viewer -> its inner rerun_notebook.Viewer widget
  • pyvista Plotter -> a self-contained client-side (vtk.js) widget (via pyvista’s jupyter_backend='html' export)

Parameters

x : object

The object to coerce.

Returns

: Widget

An ipywidgets.Widget.

Raises

: TypeError

If x can’t be coerced into a Widget (the error message points to shiny’s @render.ui decorator as a fallback for objects with an HTML repr).