Skip to content

Commit 5a6f7f0

Browse files
authored
Throw a more informative error when non-ipywidget compatible objects are passed to as_widget() (#121)
1 parent 178da20 commit 5a6f7f0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

shinywidgets/_as_widget.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ def as_widget(x: object) -> Widget:
1717

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

2226
res = _as_widget(x)
2327

0 commit comments

Comments
 (0)