Skip to content

ENH: Give a clearer error for widget js. #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ def _ipython_display_(self, **kwargs):
# and the currently registered mimetypes at
# http://www.iana.org/assignments/media-types/media-types.xhtml.
data = {
'text/plain': "A Jupyter Widget",
'text/plain': repr(self),
'text/html': self._fallback_html(),
'application/vnd.jupyter.widget-view+json': {
'version_major': 2,
'version_minor': 0,
Expand Down Expand Up @@ -748,3 +749,23 @@ def _gen_repr_from_keys(self, keys):
for key in keys
)
return '%s(%s)' % (class_name, signature)

def _fallback_html(self):
return _FALLBACK_HTML_TEMPLATE.format(widget_type=type(self).__name__)


_FALLBACK_HTML_TEMPLATE = """\
<p>Failed to display Jupyter Widget of type <code>{widget_type}</code>.</p>
<p>
If you're reading this message in Jupyter Notebook or JupyterLab, it may mean
that the widgets JavaScript is still loading. If this message persists, it
likely means that the widgets JavaScript library is either not installed or
not enabled. See the <a href=https://ipywidgets.readthedocs.io/en/latest/user_install.html>Jupyter
Widgets Documentation</a> for setup instructions.
</p>
<p>
If you're reading this message in another notebook frontend (e.g. a static
rendering on GitHub or <a href="https://nbviewer.jupyter.org/">NBViewer</a>),
it may mean that your frontend doesn't currently support widgets.
</p>
"""