Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity does not work in Jupyter Lab #66

Closed
lschr opened this issue Sep 12, 2018 · 29 comments
Closed

Interactivity does not work in Jupyter Lab #66

lschr opened this issue Sep 12, 2018 · 29 comments

Comments

@lschr
Copy link

lschr commented Sep 12, 2018

Everything works fine in Jupyter Notebook, but not in Jupyter Lab (version 0.34.7).

screenshot

  • Styling of the buttons does not seem to work
  • The buttons have no functionality; e.g. pressing the panning button does not enable panning

On the Javascript console I can the following error whenever the mouse pointer enters the area of the figure, which may or may not be related:

screenshot_20180912_130449

@feanor12
Copy link

I had a similar problem when I was using a notebook which had output cells with plots generated by (%matplotlib notebook)

I fixed it by:

  1. delete all output cells
  2. save notebook
  3. reload page
  4. restart kernel
  5. run with %matplotlib widget

I think that %matplotlib notebook injects some kind of javascript that kills something inside jupyter lab.

@lschr
Copy link
Author

lschr commented Sep 12, 2018

@feanor12 Thanks, it looks like you are right. After restarting and clearing all output, the buttons work (except for the "power" button, which has already been reported in #61) and also the mouse pointer coordinates are shown properly in the bottom right corner.

The buttons still look Windows 95-ish, though (not sure if this is a bug).

@feanor12
Copy link

So maybe this is the cause for #62 as well.

@MerlinPendragon
Copy link

@feanor12 Yes!

@pdeitel
Copy link

pdeitel commented Sep 15, 2018

Is this supposed to work with Matplotlib FuncAnimations too? All I get is a blank output and the FuncAnimation itself--which works just fine in IPython in a Terminal window--does not call the update function I defined for each frame. Thanks in advance for any suggestions.

EDIT: FuncAnimation works if the frames argument is an integer. It does not work if it's a generator function, which is what I am trying to use.

@tacaswell
Copy link
Member

@pdeitel that is extremely odd. I am a bit worried that your generator is raising someplace and the exceptions are getting snarfed incorrectly. Internally, the animation module homgonizes all the input to generators (an integer gets turned into range).

@tacaswell
Copy link
Member

I think that %matplotlib notebook injects some kind of javascript that kills something inside jupyter lab.

Yes, all of the js to make the plot interactive is inserted by the notebook backend (which is why it does not work in jlab as they have closed that convenient but large security hole).

@goiosunsw
Copy link

Additionally to @feanor12's recipe I had to close all tabs on the right hand side (open notebooks). Probably their javascript was still interfering with ipympl

@mischki
Copy link

mischki commented Dec 18, 2018

Same problem and clearing outputs, restarting etc doesn't work. Any ideas? I've tried this in Chrome, Safari..

@pdeitel
Copy link

pdeitel commented Dec 18, 2018

@pdeitel that is extremely odd. I am a bit worried that your generator is raising someplace and the exceptions are getting snarfed incorrectly. Internally, the animation module homgonizes all the input to generators (an integer gets turned into range).

I have not gone back to try this again recently, but I will be sometime in the next two weeks. I have all exceptions dumping text so I can see the problems that occur, so there should not be any getting "snarfed".

@amueller
Copy link

Seems related so adding here:
If I try

% matplotlib widget

in a notebook that had %matplotlib notebook before, I get

Warning: Cannot change to a different GUI toolkit: widget. Using notebook instead.

I understand this to mean "use % matplotlib notebook instead" which seems bad advice. Maybe that's not what it means?
I know I'm doing it wrong, but I think the warning is misleading.

@dopplershift
Copy link

It means once you’ve run %matplotlib notebook, you can’t later switch to %matplotlib widget (because the two will use different event loops). You need to only ever use one or the other while the kernel is running.

Open to suggestions to language that would make that more clear, but unfortunately that’s exactly what the existing message says to me (but then again I’ve been doing this for way too long).

@amueller
Copy link

amueller commented Jan 29, 2019

Hm that's not what I understood from the message, and you can't use notebook at all in jupyter lab so the second sentence is confusing.
I would just say "Cannot change to different GUI toolkit widget from toolkit notebook" or "after already activating toolkit notebook"?
Or just your explanation "Can't change to toolkit widget since you already ran %matplotlib notebook"

@amueller
Copy link

amueller commented Jan 29, 2019

I think I might have misread "using" as "use" on my first read which probably added to the confusion, so feel free to ignore me.

@thomasaarholt
Copy link
Contributor

The warning should probably explain why it cannot change backend, or at least how the user can use a different one.

My suggestion below is verbose, but I think 50% of basic users have probably encountered this error message and then become very confused or worried.

How about changing

Warning: Cannot change to a different GUI toolkit: widget. Using notebook instead.

to

Warning: Cannot change GUI toolkit from notebook to widget. 
Only the inline and *one* interactive toolkit can be used together. 
Restart kernel to use a different toolkit.

@pdeitel
Copy link

pdeitel commented Jan 29, 2019 via email

@tobiasjj
Copy link

tobiasjj commented Feb 5, 2019

Probably another solution, which works for me in both, notebook and jupyterlab (up to version 0.35.4):

import matplotlib
matplotlib.use('module://ipympl.backend_nbagg')

from matplotlib import pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3], [4,3,2])
fig.show()

@yt87
Copy link

yt87 commented Feb 24, 2019

I still see the behaviour as described by @MerlinPendragon in his original post issue #62 on Firefox. On Chromium the example runs fine.

I am on Fedora 29.

$ conda list | grep jupyter                       
jupyter                   1.0.0                      py_1    conda-forge
jupyter_client            5.2.4                      py_0    conda-forge
jupyter_console           6.0.0                      py_0    conda-forge
jupyter_core              4.4.0                      py_0    conda-forge
jupyterlab                0.35.3                   py37_0  
jupyterlab_launcher       0.13.1                     py_2    conda-forge
jupyterlab_server         0.2.0                    py37_0

$ rpm -q firefox
firefox-64.0-4.fc29.x86_64

$ jupyter labextension list                       
JupyterLab v0.35.3
Known labextensions:
   app dir: /mnt/sdc1/home/gtrojan/miniconda3/envs/devel/share/jupyter/lab
        @deathbeds/jupyterlab-fonts v0.6.0  enabled  OK
        @jupyter-widgets/jupyterlab-manager v0.38.1  enabled  OK
        @pyviz/jupyterlab_pyviz v0.6.4  enabled  OK
        jupyter-matplotlib v0.3.0  enabled  OK
        jupyterlab_vim v0.10.1  enabled  OK

@steviestevepy
Copy link

import matplotlib
matplotlib.use('module://ipympl.backend_nbagg')

This solution worked form me, only after restarting the kernel and jupyterlab.
Looks like the widget function has bugs. After manipulating the graph and then hitting the button to turn off interactivity the graph goes all fuzzy and turns to black and white.
I don't know what the issue is for that

@flutefreak7
Copy link

flutefreak7 commented Mar 20, 2019

What about:

Matplotlib is currently configured to use the notebook backend which is suitable for the classic Jupyter Notebook and derivatives (and does not work in JupyterLab). Matplotlib does not support changing from the notebook backend to the widget backend while the kernel is running. To use the widget backend, which is supported by JupyterLab, it is recommended that you restart your kernel and clear all output cells. See (insert helpful link to docs) for details.

edit: I'm trying to make a point that brevity is not always helpful when something critical breaks. This reminds me of the classic "Unable to find VCVARSALL.BAT" error message. It tells you exactly what went wrong, but not the obvious helpful things you need to know to fix it.

@changjiong
Copy link

It means once you’ve run %matplotlib notebook, you can’t later switch to %matplotlib widget (because the two will use different event loops). You need to only ever use one or the other while the kernel is running.

Open to suggestions to language that would make that more clear, but unfortunately that’s exactly what the existing message says to me (but then again I’ve been doing this for way too long).

right, just restart the kernal and run %matplotlib widget

@cottrell
Copy link

cottrell commented Nov 13, 2019

None of the suggestions work currently. This was working recently.

Only see the text:

Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …

@martinRenou
Copy link
Member

@cottrell can you tell us how you installed ipympl? You might have missed an installation step.

I think this issue should be closed. ipympl does work in JupyterLab now.

@jasongrout
Copy link
Contributor

I think this issue should be closed. ipympl does work in JupyterLab now.

As you wish. @cottrell, feel free to open a new issue with more comprehensive information about your environment and a reproducible test case.

@cottrell
Copy link

Interesting ... I just tried at home on a Linux system (again following https://stackoverflow.com/questions/50149562/jupyterlab-interactive-plot) and everything works again.

Will try again on the work setup ... likely some interaction or version issue.

@Chang-Hsinyi
Copy link

Hi,

I use %matplotlib ipympl, all the functions can work, exclude resize function at the below right corner.
Does anyone know what the problem is, and how can I fix it? thanks

@ijpulidos
Copy link

I'm still facing the issue here. All I get is that Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …

Jupyterlab 2.1.4
ipympl 0.5.6

You can find the Pipfile and Pipfile.lock files in https://gist.github.com/ijpulidos/81edbe253bdbbe270e94a0eff75f34c0 (using pipenv to manage the environment)

@ijpulidos
Copy link

Ok, had to manually run jupyter labextension install @jupyter-widgets/jupyterlab-manager@2 for them to work. Not really sure why or how all of this works, but that did it for me.

@anoetzli
Copy link

Ok, had to manually run jupyter labextension install @jupyter-widgets/jupyterlab-manager@2 for them to work. Not really sure why or how all of this works, but that did it for me.

Thank you - this solution worked for me on
Jupyerlab 2.2.4
ipympl 0.5.7

orena1 added a commit to orena1/ipympl that referenced this issue Nov 23, 2020
All of those are because they did not restart JupyterLab
matplotlib#275
matplotlib#148
matplotlib#66
matplotlib#201

Happened to me also, It might make people run back to  notebook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests