Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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.
21 changes: 0 additions & 21 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ def _ipython_display_(self, **kwargs):
# http://www.iana.org/assignments/media-types/media-types.xhtml.
data = {
'text/plain': repr(self),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to ensure this never gets too big, how about repr(self)[:160] (or some other appropriate number).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is nice to have the full repr available, I'm just arguing whether that should be the fallback format or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you can always do repr() to get the full repr, I think chopping it off (and appending an ellipsis) is a good compromise for the fallback.

'text/html': self._fallback_html(),
'application/vnd.jupyter.widget-view+json': {
'version_major': 2,
'version_minor': 0,
Expand Down Expand Up @@ -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 = """\
<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>
"""