Skip to content

Commit e1e0948

Browse files
authored
Merge pull request #2007 from jasongrout/removehtml
Delete html fallback message.
2 parents 20466b7 + fc173e8 commit e1e0948

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

docs/source/user_install.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ running the `jupyter lab clean` command which will remove the staging and
6464
static directories from the lab directory. The location of the lab directory
6565
can be queried by executing the command `jupyter lab path` in your terminal.
6666

67+
Frequently Asked Questions
68+
--------------------------
69+
70+
**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?
71+
72+
**Answer**: A text representation of the widget is printed if the widget control
73+
is not available. It may mean the widget JavaScript is still loading. If the
74+
message persists in the Jupyter Notebook or JupyterLab, it likely means that the
75+
widgets JavaScript library is either not installed or not enabled. See the
76+
installation instructions above for setup instructions.
77+
78+
If you see this message in another frontend (for example, a static rendering on
79+
GitHub or <a href="https://nbviewer.jupyter.org/">NBViewer</a>), it may mean
80+
that your frontend doesn't currently support widgets.

ipywidgets/widgets/widget.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,16 @@ def _ipython_display_(self, **kwargs):
701701
"""Called when `IPython.display.display` is called on the widget."""
702702
if self._view_name is not None:
703703

704+
plaintext = repr(self)
705+
if len(plaintext) > 110:
706+
plaintext = plaintext[:110] + '…'
704707
# The 'application/vnd.jupyter.widget-view+json' mimetype has not been registered yet.
705708
# See the registration process and naming convention at
706709
# http://tools.ietf.org/html/rfc6838
707710
# and the currently registered mimetypes at
708711
# http://www.iana.org/assignments/media-types/media-types.xhtml.
709712
data = {
710-
'text/plain': repr(self),
711-
'text/html': self._fallback_html(),
713+
'text/plain': plaintext,
712714
'application/vnd.jupyter.widget-view+json': {
713715
'version_major': 2,
714716
'version_minor': 0,
@@ -749,23 +751,3 @@ def _gen_repr_from_keys(self, keys):
749751
for key in keys
750752
)
751753
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 the Jupyter Notebook or JupyterLab Notebook, 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/stable/user_install.html">Jupyter
764-
Widgets Documentation</a> for setup instructions.
765-
</p>
766-
<p>
767-
If you're reading this message in another frontend (for example, 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)