Skip to content

Delete html fallback message. #2007

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 3 commits into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions docs/source/user_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://nbviewer.jupyter.org/">NBViewer</a>), it may mean
that your frontend doesn't currently support widgets.
26 changes: 4 additions & 22 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +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/html': self._fallback_html(),
'text/plain': plaintext,
'application/vnd.jupyter.widget-view+json': {
'version_major': 2,
'version_minor': 0,
Expand Down Expand Up @@ -749,23 +751,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 = """\
<p>Failed to display Jupyter Widget of type <code>{widget_type}</code>.</p>
<p>
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 <a href="https://ipywidgets.readthedocs.io/en/stable/user_install.html">Jupyter
Widgets Documentation</a> for setup instructions.
</p>
<p>
If you're reading this message in another frontend (for example, 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>
"""