53

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)
Thomas K
  • 35,785
  • 7
  • 76
  • 82
Cliff Chew
  • 726
  • 1
  • 6
  • 15
  • 1
    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 Apr 01 '16 at 16:56
  • 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 Apr 03 '16 at 11:11
  • @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 Apr 05 '16 at 03:30
  • @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 Apr 05 '16 at 03:53
  • 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 Apr 05 '16 at 04:02
  • Thanks! @roadrunner66 I shall take a look the in-build sliders you mentioned! – Cliff Chew Apr 05 '16 at 04:24
  • @CliffChew it happened to me when working with plot.ly graphs as well. That seems to be the common factor here. – nluigi Apr 05 '16 at 04:33

7 Answers7

98

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.

Polyov
  • 2,123
  • 2
  • 22
  • 36
Elaine Hale
  • 1,158
  • 8
  • 10
  • 5
    Note to those using virtual environments (including conda environments): the recommended way to activate the extension is to run "jupyter nbextension enable --py --sys-prefix widgetsnbextension" in any environment where you want the Jupyter server to display widgets (to associate the extension with the env's Python). Alas, this is not very clear in the docs. See: https://github.com/jupyter-widgets/ipywidgets/issues/54. – Tom Loredo Apr 13 '18 at 05:15
  • Great it worked for me using jupyter nbextension enable --py widgetsnbextension, however I can't see plotly graphs. Anybody has the same problem? – GSandro_Strongs May 24 '21 at 16:18
33

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

jupyter labextension install @jupyter-widgets/jupyterlab-manager
Alexander Svetly
  • 1,392
  • 14
  • 14
6

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.

Pierz
  • 4,579
  • 35
  • 45
3

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.

5agado
  • 2,275
  • 2
  • 17
  • 28
2

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

nluigi
  • 1,130
  • 13
  • 28
  • Hi @nluigi, in the end were you able to resolve your issue? I had to include plot.ly into my ipython notebook. Even removing the `display()` functions, the refactoring my code as advised, my ipython notebook sliders broke today. I copied my entire script into a different notebook, and my sliders worked again. A bit of a hassle, but at least it resolves my current issue. I am not sure if it's a cache issue or anything on my browser. I am using a MacBook Pro, and running my notebooks on Chrome. – Cliff Chew Apr 08 '16 at 13:57
  • 1
    @CliffChew - no sorry, i tried reproducing the similar issue i had but couldn't. It doesn't seem to be a cache issue though. Have you tried contacting the authors of plot.ly and ask about this bug? – nluigi Apr 08 '16 at 14:11
  • @nuligi Thanks for your reply! Currently the situation isn't mission critical for me yet, as I have to move on to other aspects of my work. My "copying" method, although cumbersome, is a stop-gap measure that I can live with for now. I may look into it in some time later, and will update it here if I have any progress on this. – Cliff Chew Apr 10 '16 at 04:37
  • @CliffChew I've had exactly the same issue. Both with plotly and matplotlib. If you find the answer pls post it here! Would love to know what the bug is. Atm I've also resorted to the "copy solution". – Michael Berry Apr 18 '16 at 11:15
  • Hi @MichaelBerry, unfortunately, I am currently stuck with the same solution for now, as I have to shift my efforts to a different report. Will update here if I find any other solutions. – Cliff Chew Apr 20 '16 at 06:25
  • 1
    @MichaelBerry, recently when I look back at my scripts, I did a bit of testing, and I realise this problem doesn't appear when I use `jupyter notebook`, instead of `ipython notebook`. You can see if this helps with your situation as well? Sorry I took so long... – Cliff Chew May 13 '16 at 08:58
0

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/jupyterlab-manager@3.0.0-alpha.2
[...]
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/jupyterlab-manager@2.0
splatte
  • 1,894
  • 1
  • 12
  • 18
0

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.

Eyshika
  • 489
  • 6
  • 14