Skip to content

Commit 1bc4a67

Browse files
authored
Merge pull request #1674 from ssanderson/clearer-no-javascript-error
ENH: Give a clearer error for widget js.
2 parents 69fc950 + 7935344 commit 1bc4a67

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

ipywidgets/widgets/widget.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ def _ipython_display_(self, **kwargs):
707707
# and the currently registered mimetypes at
708708
# http://www.iana.org/assignments/media-types/media-types.xhtml.
709709
data = {
710-
'text/plain': "A Jupyter Widget",
710+
'text/plain': repr(self),
711+
'text/html': self._fallback_html(),
711712
'application/vnd.jupyter.widget-view+json': {
712713
'version_major': 2,
713714
'version_minor': 0,
@@ -748,3 +749,23 @@ def _gen_repr_from_keys(self, keys):
748749
for key in keys
749750
)
750751
return '%s(%s)' % (class_name, signature)
752+
753+
def _fallback_html(self):
754+
return _FALLBACK_HTML_TEMPLATE.format(widget_type=type(self).__name__)
755+
756+
757+
_FALLBACK_HTML_TEMPLATE = """\
758+
<p>Failed to display Jupyter Widget of type <code>{widget_type}</code>.</p>
759+
<p>
760+
If you're reading this message in Jupyter Notebook or JupyterLab, it may mean
761+
that the widgets JavaScript is still loading. If this message persists, it
762+
likely means that the widgets JavaScript library is either not installed or
763+
not enabled. See the <a href=https://ipywidgets.readthedocs.io/en/latest/user_install.html>Jupyter
764+
Widgets Documentation</a> for setup instructions.
765+
</p>
766+
<p>
767+
If you're reading this message in another notebook frontend (e.g. a static
768+
rendering on GitHub or <a href="https://nbviewer.jupyter.org/">NBViewer</a>),
769+
it may mean that your frontend doesn't currently support widgets.
770+
</p>
771+
"""

0 commit comments

Comments
 (0)