Jupyter Lab ipywidgets no longer work with ipympl?

I have consistently used the following workflow for fully updating my Jupyter Lab working environments:

$ rmvirtualenv my_env
$ mkvirtualenv --python=`which python` my_env
[my_env] $ pip install -r requirements.txt
[my_env] $ jupyter lab build
[my_env] $ jupyter lab

Recently however, after these steps:

  1. My widgets all become non-functional. I can operate and interact with them, but the figures they control do not change at all.
  2. All of the widget controls move from being above the figure they control to to below it.

Projects in virtualenvs that have not been recently updated in this way continue to work fine, and updating them reliably makes them stop working.

This occurs consistently (I have now ruined half a dozen projects confirming the pattern), and even for notebooks hosted outside my local machine (such as this one hosted on Binder). Control widgets themselves seem to work fine though (e.g., in notebooks like this one) when ipympl is not involved. I have also confirmed that the observed behavior is independent of browser and local machine (at least macOS vs iOS).

Has something about Jupyter Lab, ipywidgets, or ipympl changed recently that might be causing this?


Typical post update (non-working) configuration:

$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.4.0
ipykernel        : 6.13.1
ipywidgets       : 7.7.0
jupyter_client   : 7.3.4
jupyter_core     : 4.10.0
jupyter_server   : 1.17.1
jupyterlab       : 3.4.3
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : not installed
traitlets        : 5.2.2

$ jupyter labextension list 
JupyterLab v3.4.3
/Users/Rax/Documents/Projects/Coding/Python/venvs/picollisions/share/jupyter/labextensions
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
        nbdime-jupyterlab v2.1.1 enabled OK
        jupyter-matplotlib v0.11.1 enabled OK
        @jupyterlab/git v0.37.1 enabled OK (python, jupyterlab-git)
        @jupyter-widgets/jupyterlab-manager v3.1.0 enabled OK (python, jupyterlab_widgets)
        @kiteco/jupyterlab-kite v2.0.2 enabled OK (python, jupyterlab_kite)

Other labextensions (built into JupyterLab)
   app dir: /Users/Rax/Documents/Projects/Coding/Python/venvs/picollisions/share/jupyter/lab

Typical pre update (working) configuration:

$ jupyter --version
jupyter core     : 4.7.1
jupyter-notebook : 6.4.3
qtconsole        : not installed
ipython          : 7.26.0
ipykernel        : 6.2.0
jupyter client   : 6.1.12
jupyter lab      : 3.1.10
nbconvert        : 6.1.0
ipywidgets       : 7.6.4
nbformat         : 5.1.3
traitlets        : 5.0.5

jupyter labextension list
JupyterLab v3.1.10
/Users/Rax/Documents/Projects/Coding/Python/venvs/picollisions/share/jupyter/labextensions
        nbdime-jupyterlab v2.1.0 enabled OK
        jupyter-matplotlib v0.9.0 enabled OK
        @jupyterlab/git v0.32.2 enabled OK (python, jupyterlab-git)
        @jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
        @kiteco/jupyterlab-kite v2.0.2 enabled OK (python, jupyterlab_kite)

/usr/local/share/jupyter/labextensions
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)

Other labextensions (built into JupyterLab)
   app dir: /Users/Rax/Documents/Projects/Coding/Python/venvs/picollisions/share/jupyter/lab

Typical requirements:

#...
ipywidgets                 
ipympl

jupyterlab >=3.1                
jupyterlab-git                 
jupyterlab-kite >=2.0.2        

(I’ve tried omitting Kite to see if that was the culprit. In any case it is not present in the Binder versions.)

Cross-posted here and here.


Isn’t this the same issue where matplotlib and ipywidgets are not working in conjunction reported here?


Oddly, the one you say doesn’t work, still works from here.

It still has ipywidgets 7.6.3. Did you try pinning to that?

@fomightez I gather the solution to that is ipywidgets <7.7? In any case I tried that and it doesn’t fix things.

My update above works and has ipywidgets 7.6.3. I think pinning ipywidgets, ipympl, and matplotlib to the versions you posted about working should help then? (Maybe. However, @jupyter-widgets/jupyterlab-manager may still cause issues?)

@fomightez Can you list the relevant versions that are working for you?

What I am getting in current launches from here where at present your notebook that comes up still runs without anything in it changed:

!jupyter --version
jupyter core     : 4.7.1
jupyter-notebook : 6.3.0
qtconsole        : not installed
ipython          : 7.26.0
ipykernel        : 6.0.3
jupyter client   : 6.1.12
jupyter lab      : 3.1.1
nbconvert        : 6.0.7
ipywidgets       : 7.6.3
nbformat         : 5.1.3
traitlets        : 5.0.5
!jupyter labextension list 
JupyterLab v3.1.1
/srv/conda/envs/notebook/share/jupyter/labextensions
        jupyter-offlinenotebook v0.2.1 enabled OK
        jupyterlab-link-share v0.2.0 enabled OK (python, jupyterlab-link-share)
        nbdime-jupyterlab v2.1.0 enabled OK
        jupyter-matplotlib v0.9.0 enabled OK
        @jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
        @jupyter-server/resource-usage v0.6.0 enabled OK (python, jupyter-resource-usage)

Other labextensions (built into JupyterLab)
   app dir: /srv/conda/envs/notebook/share/jupyter/lab

Truncated pip list

%pip list
Package                       Version
----------------------------- -------------------
...
ipympl                        0.7.0
ipython                       7.26.0
ipython-genutils              0.2.0
ipywidgets                    7.6.3
jedi                          0.18.0
Jinja2                        3.0.1
json5                         0.9.5
jsonschema                    3.2.0
jupyter-client                6.1.12
jupyter-core                  4.7.1
jupyter-offlinenotebook       0.2.1
jupyter-resource-usage        0.6.0
jupyter-server                1.10.1
jupyter-server-mathjax        0.2.3
jupyter-telemetry             0.1.0
jupyterhub                    1.4.2
jupyterlab                    3.1.1
jupyterlab-link-share         0.2.0
jupyterlab-pygments           0.1.2
jupyterlab-server             2.6.1
jupyterlab-widgets            1.0.0
kiwisolver                    1.3.2
Mako                          1.1.4
MarkupSafe                    2.0.1
matplotlib                    3.4.3
matplotlib-inline             0.1.2
...
1 Like

Your launches from the one that wasn’t working (here), with the newer version of the modules and labmanager extension work if you add fig.canvas.draw() as the last line of plot_logisitic, as suggested by @ianhi here.

Interestingly, this is a nice parallel to updates in ipywidgets over the last few years causing others to have to revisit & update their old code to more explicit and follow current best practice as well. (I’m specifically, talking about other cases. Not among the examples in this post.)

@fomightez Excellent: that fixes it!

1 Like

Hi @fomightez,

I’m also getting the “Javascript Error: IPython is not defined” error, but I’m not sure where fig.canvas.draw(). Please take a look at the screenshots below. TIA!

Selected Jupyter core packages…
IPython : 8.21.0
ipykernel : 6.29.1
ipywidgets : 8.1.1
jupyter_client : 8.6.0
jupyter_core : 5.7.1
jupyter_server : 2.12.5
jupyterlab : 4.1.0
nbclient : 0.8.0
nbconvert : 7.15.0
nbformat : 5.9.2
notebook : not installed
qtconsole : not installed
traitlets : 5.14.1

This is probably a different issue than where you posted this.

Did you run %pip install ipympl and then restart the kernel and refresh your browser? (Preferably shut down both JupyterLab and your browser and restart everything after that.)

Then run your code with %matplotlib ipympl as the first cell with no other %matplotlib-containting lines? I cannot tell because you share a little snipper of code as screenshot. Both of those approaches make it hard to advise you. Please search on here for more about ipympl and try the code examples you find. Then maybe you provide more streamlined code that shows the same issue? Like a ‘toy’ example that parallels your approach to the part you have trouble with displaying. Note because you show only a fragment of stuff with no actual code provided, I cannot even tell if you need ipympl for this but based on where you put this and the note about javascript that is my assumption.

I have done some demos that use Funcanimation() here but I don’t know if those involve JupyterLab, and I don’t generally combine it with using a trigger button. If I had a better idea of your goals, I may be able to find among my collected resources a more appropriate example that does indeed use that.

Also pay close attention to the warning. Even if you had your code and environment ready to run, the warning is stressing to you, that ‘as-is’ ,you essentially discard the animation without rendering it.

Please read and follow Getting good answers to your questions. The section at the end includes a link to How do I ask a good question? which emphasizes how to share code and errors as text and not screenshots under a section entitled ‘Help others reproduce the problem’.

Please in the future don’t tag on to solved two-year old threads.