From be2ab42feab688061ec24f42efb17db8b9b0ef3e Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Tue, 20 Mar 2018 11:00:30 -0700 Subject: [PATCH 1/3] Delete html fallback message. This reverts #1674, since we discovered some problems with the classic notebook and html outputs. Fixes #1777 Fixes #1951 --- ipywidgets/widgets/widget.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ipywidgets/widgets/widget.py b/ipywidgets/widgets/widget.py index e5abef8ee0..6e3f425024 100644 --- a/ipywidgets/widgets/widget.py +++ b/ipywidgets/widgets/widget.py @@ -708,7 +708,6 @@ def _ipython_display_(self, **kwargs): # http://www.iana.org/assignments/media-types/media-types.xhtml. data = { 'text/plain': repr(self), - 'text/html': self._fallback_html(), 'application/vnd.jupyter.widget-view+json': { 'version_major': 2, 'version_minor': 0, @@ -749,23 +748,3 @@ 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 = """\ -

Failed to display Jupyter Widget of type {widget_type}.

-

- If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, 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 Jupyter - Widgets Documentation for setup instructions. -

-

- If you're reading this message in another frontend (for example, a static - rendering on GitHub or NBViewer), - it may mean that your frontend doesn't currently support widgets. -

-""" From 48c508a4508d74266f90ec9f39460e7f5e475392 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Tue, 20 Mar 2018 11:16:59 -0700 Subject: [PATCH 2/3] Add documentation help for widgets not displaying. --- docs/source/user_install.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/source/user_install.md b/docs/source/user_install.md index 037252c58f..f1b40856a2 100644 --- a/docs/source/user_install.md +++ b/docs/source/user_install.md @@ -64,3 +64,17 @@ running the `jupyter lab clean` command which will remove the staging and static directories from the lab directory. The location of the lab directory can be queried by executing the command `jupyter lab path` in your terminal. +Frequently Asked Questions +-------------------------- + +**Question**: When I display a widget or interact, I just see some text, such as `IntSlider(value=0)` or `interactive(children=(IntSlider(value=0, description='x', max=1), Output()), _dom_classes=('widget-interact',))`. What is wrong? + +**Answer**: A text representation of the widget is printed if the widget control +is not available. It may mean the widget JavaScript is still loading. If the +message persists in the Jupyter Notebook or JupyterLab, it likely means that the +widgets JavaScript library is either not installed or not enabled. See the +installation instructions above for setup instructions. + +If you see this message in another frontend (for example, a static rendering on +GitHub or NBViewer), it may mean +that your frontend doesn't currently support widgets. From fc173e89fa4ec1b336a76f6070fdd02d33ce0ccd Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 23 Mar 2018 12:44:41 -0700 Subject: [PATCH 3/3] Chop off fallback text representation to around 110 characters. This prevents huge text output when it is a fallback. Length 110 is chosen as it fits on a single line in the classic Notebook. --- ipywidgets/widgets/widget.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipywidgets/widgets/widget.py b/ipywidgets/widgets/widget.py index 6e3f425024..b504793bb3 100644 --- a/ipywidgets/widgets/widget.py +++ b/ipywidgets/widgets/widget.py @@ -701,13 +701,16 @@ def _ipython_display_(self, **kwargs): """Called when `IPython.display.display` is called on the widget.""" if self._view_name is not None: + plaintext = repr(self) + if len(plaintext) > 110: + plaintext = plaintext[:110] + '…' # The 'application/vnd.jupyter.widget-view+json' mimetype has not been registered yet. # See the registration process and naming convention at # http://tools.ietf.org/html/rfc6838 # and the currently registered mimetypes at # http://www.iana.org/assignments/media-types/media-types.xhtml. data = { - 'text/plain': repr(self), + 'text/plain': plaintext, 'application/vnd.jupyter.widget-view+json': { 'version_major': 2, 'version_minor': 0,