54
votes

I created a table with an interactive slider that allows me to toggle between different periods on my table. It was working for the past few days, until today, when I re-ran the notebook, the slide bar doesn't show anymore. No error messages appear. The code seem to run just fine, as the table appears, but the slide bar just doesn't appear. I didn't change my code either, as I was working on a separate part of my notebook.

I tried many approaches, including searching in this space but was still unable to come up with a solution. I was wondering if anyone faced a similar issue, and have any solution to this.

Below is my code snippet. Anything before was solely to get my data into the desired form for tabulation.

from IPython.display import display
from ipywidgets import widgets, interactive
v = interactive(by_q, quarter=(['q1y2015', 'q2y2015', 'q3y2015', 'q4y2015']), days=(1, 180))
display(v)
7
Could you add your function by_q to make a complete example? Normally you don't even need to assign interactive to a variable and then call display(v). - roadrunner66
I had this same strange bug with interact a couple of days ago... unfortunately it disappeared as mysteriously as it appeared. I don't have a solution for it. Perhaps try %reset -f at the top of your notebook? - nluigi
@nluigi I am not sure if it was some package conflicts that I have, as I am exploring Plot.ly on the same notebook as well. My current very inefficient way of dealing with this situation when it arises is to copy the cells into a new notebook, and the slider would work again on the new notebook. Unfortunately, as I am trying to move fast with my data, I don't have too much time to debug the situation as of now. I shall try your suggestion when it comes up again. Thanks! - Cliff Chew
@roadrunner66, thanks, you are right! The essence of my function goes as such: def by_q(days=1, quarter="q1y2015 "): q = test_2015[test_2015.signup_yr_q==quarter] q_days = q[(q.signup_to_offer < datetime.timedelta(days = days)) | (q.signup_to_list < datetime.timedelta(days = days))] return q_days The dataframe appears, but not slider bar. Yet, no error messages appear as well. As mentioned above, I am settling for copying codes into a separate notebook for now. Sorry if I fumble a bit here guys! Thanks for your kind patience! - Cliff Chew
These are the standard imports I use for most of my Jupyter notebooks with sliders: %matplotlib inline from __future__ import division from ipywidgets import * import numpy as np import matplotlib.pyplot as p . Then I just call interact (function, arg1=(0,100,1), arg2=(0,100,1), etc.) . Make sure you have the latest distribution. I use Anaconda and update most packages about once a month, since Jupyter is still being heavily developed. - roadrunner66

7 Answers

99
votes

With the new version of ipywidgets, I ran into this problem, but then I found on their github readme that you now need to follow

pip install ipywidgets

with

jupyter nbextension enable --py widgetsnbextension

That cleared the problem up for me.

33
votes

After googling for a while without hope, I realized that I need

jupyter labextension install @jupyter-widgets/jupyterlab-manager
7
votes

If you've already got [an older version] of ipywidgets installed in Jupyter and you're seeing this problem (you'll probably be seeing javascript errors in the browser console) then you need to run the install command to update the relevant files e.g.:

jupyter nbextension install --user --py widgetsnbextension

And you may also need to rerun the enable command e.g.:

jupyter nbextension enable --user --py widgetsnbextension

Note: the --user argument may need to be different if you're using a virtualenv or other environment - see the ipywidget docs for more details.

3
votes

Might have been a stupid mistake of mine, but in case you are using virtual environments, just keep properly in mind what is running from where.

You might properly run Jupyter from inside your current environment every time as needed, or might have a root env from which you always start the Jupyter you will end up using for all your environments.

For the latter case, what you need to be sure is to enable nbextension for the Jupyter you are actually running, instead of mistakenly run the command from within your currently active environment.

2
votes

I think plot.ly imports a function called display which overrides the function display from ipython. Try changing the order of imports or simply import the function under a different name

1
votes

Adding to Alexander Svetly's answer, running:

jupyter labextension install @jupyter-widgets/jupyterlab-manager

seemed to get stuck, by adding --debug I was able to see where:

jupyter labextension install --debug @jupyter-widgets/jupyterlab-manager
[...]
npm notice 📦  @jupyter-widgets/[email protected]
[...]
Fetching URL: https://registry.yarnpkg.com/@jupyter-widgets%2Fjupyterlab-manager

Looks like it's trying to install version 3 but I am using version 2.2.9 of Jupyter Lab, so what finally worked was:

jupyter nbextension enable --py widgetsnbextension --sys-prefix
jupyter labextension install --debug @jupyter-widgets/[email protected]
0
votes

Apparently, if you are trying to use it on the virtual environment and running on vscode , then jupyter notebook itself doesn't work that efficiently but it works on using ipython <notebook_name>, but in that case you won't be able to visualize widgets. So the best way is to do jupyter notebook <notebook name>, which will open notebook on chrome, and then change the kernel first, i.e. choose your virtual environment and run on the chrome.