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

On() event handling not working in Jupyter notebook on both Windows and Linux #296

Open
kobussch opened this issue Nov 2, 2019 · 6 comments

Comments

@kobussch
Copy link

kobussch commented Nov 2, 2019

I am trapping the on-click event on a plotlyjs graph. In the REPL everything works fine, but in n Jupyter notebook there is no sign of an event happening. The plot renders correctly in Jupyter and all the built-in interactive functions work correctly (zoom, hover display etc.). It is only my own custom on-click function that never gets called.

Context

The following code was used:

using PlotlyJS,WebIO

p1=plot(rand(10));
on(p1["click"]) do data
  global bp1 += 1
end;

bp1 = 0
0
display(p1);
# when the plot launches in Blink/Electron, click a couple of times on data points 
#(actually anywhere in the plot as long as a hover cursor is showing that a data point is being tracked)
# now look at the content of the global variable
bp1
2

The global gp1 should update with each click. Running the above code in REPL works fine. In Jupyter I have split the code into three cells with the using statement in the 1st, everything else in the 2nd cell except for the final bp1 which goes in the 3rd cell. Then I run the first two cells, The plot correctly renders, but no matter how many time I click in the plot area, when executing the 3rd cell, bp1 always returns 0.

This used to work, but after upgrading packages it stopped working

Versions

Windows 10 Home
Julia V1.3.0-rc4
[f0f68f2c] PlotlyJS v0.13.0
[0f1e0344] WebIO v0.8.11
[7073ff75] IJulia v1.20.0
conda 4.7.12 (miniconda installed via WebIO/IJulia)
jupyter:
jupyter core : 4.6.0
jupyter-notebook : 6.0.1
qtconsole : 4.5.5
ipython : 7.8.0
ipykernel : 5.1.2
jupyter client : 5.3.4
jupyter lab : not installed
nbconvert : 5.6.0
ipywidgets : 7.5.1
nbformat : 4.4.0
traitlets : 4.3.3

@sglyon
Copy link
Member

sglyon commented Nov 2, 2019

Thanks for reporting and providing a clear example and good writeup!

I'm not sure exactly what happened.

I'm afraid I won't be a lot of help on this one... I don't have a windows installation that I can use for testing and nothing in this library changed.

Perhaps @travigd would know if something on the WebIO side changed?

@kobussch
Copy link
Author

kobussch commented Nov 2, 2019

Thanks Spencer for the quick reply and may I add a special thanks for this great tool. I am doing magic things with PlotlyJS and Julia thanks to you. Yes, I thought that would be your reply and yes, I will report this at WebIO as you suggest. Unfortunately Travigd has much the same problem - no Windows to test on. I, on the other hand, have no JavaScript experience. I am willing to help track this down with a bit of coaching. I agree that it is probably a WebIO problem and I hope Travigd can give some guidance. You can decide if you want to keep this issue open or close it until there is progress to report.

@sglyon
Copy link
Member

sglyon commented Nov 4, 2019

Thanks @kobussch ! It's always gratifying to hear positive feedback on open source projects. Also very cool that you are doing "magic" :)

I wish I could be more helpful, but I haven't had a ton of time lately to keep up with changes in WebIO and friends.

Because of how julia and jupyter are written and packaged, it would surprise me that this would be a windows only issue. Have you tried on another operating system?

I just checked on my linux machine and it did not work for me in jupyterlab, but did work in the standard notebook

@kobussch
Copy link
Author

kobussch commented Nov 7, 2019

I did some more tests and it is becoming quite interesting. Even though this may turn out to be a WebIO problem as previously suggested, I will post my results here in case it triggers some bright ideas somewhere.

I did an install of Julia 1.3 rc1.4 on a Linux machine on which I have previously set up Julia 1.2, PlotlyJS, IJulia and nothing else at all. This did not go smoothly (miniconda issues, missing WebIO, the usual shebang), but I will skip the nasty details for a later discussion. Eventually I got it going. The surprising outcome is that my test code worked in a Jupyter notebook, but only once. I have a test notebook previously set up with the code as per my first post. After sorting out the install issues, I opened this notebook (with Jupyter launched from the REPL) and it worked perfectly in all aspects. The graphics of the previous run displayed immediately and the click event capture worked. Then I closed the notebook and shut down the Jupyter server and repeated the exercise. This time, the saved graphics display did not work and neither did the event capture. This state is now permanent.

This may be what happened in your labbook test as well. The first time (in labbook) was successful but the second time (in notebook) not. It would be interesting to know if your labbook test still gives the same results. I am starting to think that it may have something to do with how the note/labbook is saved.

I would have ascribed this whole bizarre sequence to finger trouble, but I distinctly remember the same thing happening when I did my original Windows upgrade. It worked once.

I am planning to set up a virtual box with a completely virgin Linux install where I can record some snapshots and try out various sequences. Will keep you posted on the results.

Kobus

@sglyon
Copy link
Member

sglyon commented Nov 8, 2019

very interseting. do keep up updated

@kobussch
Copy link
Author

I can now confirm that everything in my previous comment is valid and repeatable (and broken) in both WIndows and Linux. I created a brand new VirtualBox with Linux Mint Cinnamon 19.2 and then installed Julia, PlotlyJS, etc. (latest versions as per julia Pkg system). I then created a Jupyter notebook containing the code of my first post, but did not run this notebook - only saved it and made an additional backup as reference. Now I opened this notebook again in Jupyter and executed the cells. Evrything works - the plot renders and the clicks update the global variable. If I close the notebook quickly to avoid the autosave feature, I can do this multiple times in a row and everything keeps on working. When I hit the Save and checkpoint button in the notebook (or allow autosave), that is when things go wrong. From there on, if I re-open the notebook file, the mouse click event handler never gets called again. Resetting the notebook file from the backup file restores functionality, so it is definitely not something external that goes wrong. It is all about the contents of the notebook file and whatever knock-on effects it has on the chain of interfaces from the web browser through WebIO into Julia.

I can also mention that running the using... cell and then saving does not cause problems. It is only when the plot is rendered and the output of that step is saved to the notebook file that the error occurs.

My next step in cracking this nut will be to create clean VirtualBox installs of older versions of Julia, pinning both PlotlyJS and WebIO package versions and then creep forward one update at a time to see if I can find the code change that causes the problem. Unfortunately the Julia package system has no control over the Conda, Electron and ZMQ binaries installed in the process, so this approach may not be successful. Any other ideas?

@kobussch kobussch changed the title On() event handling not working in Jupyter notebook on Windows On() event handling not working in Jupyter notebook on both Windows and Linux Nov 14, 2019
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

2 participants