matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.57k stars 227 forks source link

v0.9.0 breaks Output rendering in voila #463

Closed marcelmindemann closed 2 years ago

marcelmindemann commented 2 years ago

Describe the issue

Using an ipywidgets.Output to capture some ipympl plots, then displaying the Output in Voila shows only "Loading Widget...". Works with ipympl 0.8.8.

Minimal code example:

import matplotlib.pyplot as plt
import ipywidgets as widgets

%matplotlib widget
o = widgets.Output()

with o:
    plt.plot([1, 2, 3, 4])
    plt.ylabel('some numbers')
    plt.show()

o

Works in JupyterLab 3.3.0:

Screen Shot 2022-04-21 at 15 50 33

Does not work in voila + ipympl 0.9.0:

Screen Shot 2022-04-21 at 15 50 39

Works in voila + ipympl 0.8.8:

Screen Shot 2022-04-21 at 15 51 33

Versions

 3.9.10 (main, Feb  2 2022, 16:22:02) 
[Clang 13.0.0 (clang-1300.0.29.30)]
ipympl version: 0.8.8

Selected Jupyter core packages...
IPython          : 8.2.0
ipykernel        : 6.13.0
ipywidgets       : 7.7.0
jupyter_client   : 7.2.2
jupyter_core     : 4.10.0
jupyter_server   : 1.16.0
jupyterlab       : 3.3.4
nbclient         : 0.5.13
nbconvert        : 6.5.0
nbformat         : 5.3.0
notebook         : 6.4.11
qtconsole        : not installed
traitlets        : 5.1.1
Known nbextensions:
  config dir: /Users/marcel.mindemann/moia-dev/pooling-analytics/passt/discovery-panel/.venv/etc/jupyter/nbconfig
    notebook section
      jupyter-leaflet/extension  enabled 
      - Validating: OK
      jupyter-matplotlib/extension  enabled 
      - Validating: OK
      jupyterlab-plotly/extension  enabled 
      - Validating: OK
      voila/extension  enabled 
      - Validating: OK
      jupyter-js-widgets/extension  enabled 
      - Validating: OK
JupyterLab v3.3.4
/Users/marcel.mindemann/moia-dev/pooling-analytics/passt/discovery-panel/.venv/share/jupyter/labextensions
        jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
        jupyter-matplotlib v0.10.5 enabled OK
        jupyter-leaflet v0.16.0 enabled OK
        jupyterlab-plotly v5.7.0 enabled OK
        @pyviz/jupyterlab_pyviz v2.2.0 enabled OK (python, pyviz_comms)
        @voila-dashboards/jupyterlab-preview v2.1.5 enabled OK (python, voila)
        @jupyter-widgets/jupyterlab-sidecar v0.6.1 enabled OK (python, sidecar)
        @jupyter-widgets/jupyterlab-manager v3.1.0 enabled OK (python, jupyterlab_widgets)
martinRenou commented 2 years ago

~Can you try uninstalling ipympl, then removing the /Users/marcel.mindemann/moia-dev/pooling-analytics/passt/discovery-panel/.venv/share/jupyter/labextensions/jupyter-matplotlib directory entirely and install ipympl v0.9.0 again?~

Starting from this release, updating ipympl should be less painful.

martinRenou commented 2 years ago

@ianhi I can also reproduce this issue. Latest ipympl seems to not work with Voila.

I guess the issue is with the package version number. Voila seems to be trying to download jupyter-matplotlib 1.0.0 instead of 0.11.0:

Falling back to https://cdn.jsdelivr.net/npm/ for jupyter-matplotlib@1.0.0
ianhi commented 2 years ago

Is that maybe a bug in voila and it's widget manager?

ianhi commented 2 years ago

I wonder why this doesn't happen for ipywidgets though. As far as I can see we've done the same thing as is done there

martinRenou commented 2 years ago

Apparently there is the same issue with nbpshinx (which uses the ipywidgets HTMLManager) https://github.com/matplotlib/ipympl/issues/462

You can see in this issue's screenshots the same thing:

Falling back to https://cdn.jsdelivr.net/npm/ for jupyter-matplotlib@1.0.0
martinRenou commented 2 years ago

It's unclear to me now how Voila/nbsphinx are supposed to know which jupyter-matplotlib version they need to download if that version is not part of the Python model... So this error makes sense.

martinRenou commented 2 years ago

ipywidgets seems to be making a special case for ipywidgets...

https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/src/htmlmanager.ts#L115-L123

martinRenou commented 2 years ago

I guess our only solution is to revert https://github.com/matplotlib/ipympl/pull/448 :( I am so sorry

martinRenou commented 2 years ago

It looks like if we want to implement #448 properly we need to update ipywidgets first

DonJayamanne commented 2 years ago

similar problem in vscode as well https://github.com/microsoft/vscode-jupyter/issues/9697 @martinRenou let me know if there's anything we need to do to get this fixed in vscode extension. thanks.

martinRenou commented 2 years ago

0.9.1 should fix this issue. I will mark the 0.9.0 release as broken on conda-forge.

@ianhi I reverted your changes on the widget versioning, again I am sorry for this. Though I've loosen a bit the back-end/front-end relationship by requiring ^0.11 instead of ^0.11.1, see https://github.com/matplotlib/ipympl/blob/main/ipympl/_version.py#L3.