Skip to content

WebAgg based jupyter notebook backend #29725

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

Closed

Conversation

raphaelquast
Copy link
Contributor

@raphaelquast raphaelquast commented Mar 10, 2025

I've been playing around a bit with webagg and jupyter notebooks to finally get a backend that
fully supports the interactive features of EOmaps... (e.g. that properly supports blitting)

In the process, I've noticed that it is possible to create a quite minimalist implementation of a webagg based backend for jupyter notebooks that does the job nicely!

The idea here is the following:

  • use a ipywidgets HTML widget to <iframe> the generated webagg page into the notebook.
  • adjust the size of the widget via a ´"resize_event"` callback on the figure

This works really nice out of the box and together with #27160 it is a backend that finally supports blitting in jupyter notebooks without any lags or glitches.

Would be nice to get an opinion from your side on this idea (and if you think something like this should go into matplotlib or if this is better kept inside EOmaps and loaded with %matplotlib module://eomaps.backend_webagg_widget.

PR checklist

@raphaelquast raphaelquast changed the title Add WebAggWidget backend WebAgg based jupyter notebook backend Mar 10, 2025
@ianthomas23
Copy link
Member

This is an interesting technical approach and fine for local usage but it does not work for Jupyter notebooks in general.

At its heart Jupyter is a protocol for messages sent between a front end (web browser) and a backend (Jupyter server) that may be running on the same or different machine, and can spawn new kernel processes (e.g. python) on the same or different machines. The communication here to update the plot is using direct communication between the front end and webagg's tornado implementation, bypassing Jupyter messaging. It works fine in a local dev setup where you have the Jupyter server and kernel running on the same machine and you aren't too bothered about security. But there are many Jupyter installations (e.g. JupyterHub) in which one or both of those are no longer true.

So probably it is best not to claim that works in Jupyter. At best you will end up having to deal with questions about tornado routing and security setup, and I would not wish that on anybody!

Note that to really get the webagg backend working in Jupyter one would have to extend it to use Jupyter messaging. This is precisely what the ipympl backend is, so that problem has already been solved.

I think your ultimate motivation here is to support blitting and avoid event accumulation in Matplotlib plots in Jupyter, in which case perhaps the best approach would be to continue with #27160. It looks like that was progressing well but stalled because you didn't have time to address the review comments. If you could get that working to your satisfaction here in the webagg backend that would be great. You can ignore ipympl, someone else (possibly me) will ensure the changes are incorporated there eventually.

@raphaelquast
Copy link
Contributor Author

Thank you very much @ianthomas23 for your detailed comment! I fully agree with your view on this.

Indeed ipympl is the proper way to implement a matplotlib backend for jupyter notebooks,
and finishing #27160 such that it works for ipympl as well is the way to go here.

I can try to find the time to finish #27160 properly, but to be honest, one reason why I've lost a bit of pace is because I've been
waiting since 18 October 2023 to get some help implementing the required ack message so that the solution can be used in ipympl (#19116 (comment)) ... which was my goal here from the start.

I can fix the python-side, but I don't have the time to dig into the javascript code since it's not my expertise...
If someone (maybe you?) could create a branch in ipympl that includes the necessary changes on the javascript side, I'd be happy to make sure that the webagg event accumulation fix is implemented such that it does it's job equally well for ipympl.

To be clear, an ack message like this one should be all I need:

)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants