IPython Notebook ipywidgets does not show
Asked Answered
P

11

75

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)
Pastorship answered 1/4, 2016 at 8:3 Comment(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).Bonds
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?Edy
@Edy 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!Pastorship
@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!Pastorship
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.Bonds
Thanks! @Bonds I shall take a look the in-build sliders you mentioned!Pastorship
@CliffChew it happened to me when working with plot.ly graphs as well. That seems to be the common factor here.Edy
T
126

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

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

That cleared the problem up for me.

Tarriance answered 23/6, 2016 at 21:9 Comment(2)
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: github.com/jupyter-widgets/ipywidgets/issues/54.Guillema
Great it worked for me using jupyter nbextension enable --py widgetsnbextension, however I can't see plotly graphs. Anybody has the same problem?Columbine
F
42

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

jupyter labextension install @jupyter-widgets/jupyterlab-manager
Funds answered 2/10, 2018 at 18:10 Comment(2)
Thank you! I use jupyter lab and this was the command that worked.Bonin
Worked for me but complained about being deprecated.Rubber
S
11

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.

Store answered 2/10, 2020 at 12:4 Comment(2)
restart jupyter afterwardsForgiving
I have had to start doing this when using powershell every time I run my notebook. Is there some way to set this permanently I wonder?Adonic
C
4

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]
Claviform answered 28/11, 2020 at 7:28 Comment(0)
R
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.

Rabble answered 30/8, 2017 at 17:57 Comment(0)
C
3

For anyone still stumped after the accepted suggestions, the answer might be simple: There's a Jupyter Lab prompt to enable extensions on the Extension Manager tab (in the left panel). I did all kinds of installation steps for the python environment, but in the end I just wasn't allowing Jupyter Lab to run them apparently.

Conchita answered 30/7, 2023 at 20:55 Comment(0)
E
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

Edy answered 5/4, 2016 at 10:34 Comment(6)
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.Pastorship
@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?Edy
@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.Pastorship
@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".Henig
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.Pastorship
@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...Pastorship
G
2

Jupyterlab

To all the folks coming from jupyterlab

Jupyter 3.0 and higher

Also check the docs, but:

  1. Start a terminal with admin privileges
  2. Update your base environment, where you will run jupyterlab. conda install -n base -c conda-forge jupyterlab_widgets
  3. Update your kernel environment. conda install -n pyenv -c conda-forge ipywidgets
  4. Restart kernel

Jupyter 1 or 2

Please check steps to make it work in Jupyter 1 or 2 docs

After this restart or build the lab to see the changes

Gerry answered 24/3, 2022 at 12:59 Comment(2)
Worked flawlessly for me both in jupyter lab (through the browser) and within VS Code. Two comments that IMHO add to the answer: 1. the "jupyter --version" command will let you know which link to follow. 2. the installation commands suggested in the docs must be run from within a terminal opened with admin privileges.Babarababassu
I used the notebook in docker container created with poetry. Adding jupyterlab_widgets to poetry project solved an issue. But is was necessary to reload the window in VSC after container start(Jeane
M
1

Even though this is 6 years old, this is what worked for me. Even after using Elaine's question.

After running jupyter --version inside my conda environment, i saw this.

$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.4.0
ipykernel        : 6.9.1
ipywidgets       : 7.7.1
jupyter_client   : 7.2.2
jupyter_core     : 4.10.0
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : not installed
traitlets        : 5.4.0

So i ran:

pip install jupyterlab
pip install jupyter_server

After restarting my kernel, the widgets appeared just fine.

I hope this helps someone looking for this question, just as i did.

Milner answered 14/10, 2022 at 13:17 Comment(0)
V
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.

Vent answered 26/1, 2021 at 7:26 Comment(0)
C
0

I had similar problem while working in chrome. But when I open a same notebook in different browser (internet explorer) it is showing all the widgets just fine. Copy the url from jupyter notebook and open it in another browser, it will work.

Not sure why this is happening looking forward for help.

Cortezcortical answered 22/5, 2023 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.