Skip to content

Commit

Permalink
Throw a more informative error when non-ipywidget compatible objects …
Browse files Browse the repository at this point in the history
…are passed to `as_widget()` (#121)
  • Loading branch information
cpsievert authored Nov 17, 2023
1 parent 178da20 commit 5a6f7f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion shinywidgets/_as_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def as_widget(x: object) -> Widget:

_as_widget = AS_WIDGET_MAP.get(pkg, None)
if _as_widget is None:
raise TypeError(f"Don't know how to coerce {x} into a ipywidget.Widget object.")
msg = f"Don't know how to coerce {x} into a ipywidget.Widget object."
if callable(getattr(x, "_repr_html_", None)):
msg += " Instead of using shinywidgets to render this object, try using shiny's @render.ui decorator "
msg += " https://shiny.posit.co/py/api/ui.output_ui.html#shiny.ui.output_ui"
raise TypeError(msg)

res = _as_widget(x)

Expand Down

0 comments on commit 5a6f7f0

Please sign in to comment.