vispy / jupyter_rfb

Remote Frame Buffer for Jupyter
https://jupyter-rfb.readthedocs.io
MIT License
55 stars 10 forks source link

Snapshot functionality #37

Closed almarklein closed 2 years ago

almarklein commented 2 years ago

This makes that static renderings of the notebook (by nbsphinx, Github, etc.) include a snapshot of the canvas, which makes all examples quite a bit nicer to read.

The cost is that an intitial draw is requested when a canvas is first shown. Well worth it, I think.

Todo:

almarklein commented 2 years ago

I got this idea while musing about reviving the ipynb_static backend in vispy. But this change makes that backend type unnecessary.

djhoese commented 2 years ago

What is the series of events here? Does the sphinx notebook extension run the notebook or are you saving the examples with the output still there?

almarklein commented 2 years ago

In IPython an object can provide multiple representations. The "application/vnd.jupyter.widget-view+json" mime type sets up the connection with JS in a live session, but is not visible at all when the notebook is shown offline. This PR simply adds a "text/html" representation, which is ignored in a live session, but is shown in a static setting.

djhoese commented 2 years ago

Very cool. I had no idea.

almarklein commented 2 years ago

Hmm, it's slightly more complex. This idea does not work for nbconvert because it still prioritizes the "application/vnd.jupyter.widget-view+json" over the "text/html". Consequently it does work as I intended on Github's notebook renderer, but not for e.g. nbSphinx and nbviewer. Looking into another idea now.

almarklein commented 2 years ago

This is ready for review. This became a bit different from how it started. I hope everything is clear from the added docs and comments.

Here's also a screenshot from what an example in our docs will look like. The snapshots are just images (not interactive of course). In the live notebook, the "initial snapshot" is not visible, but the interactive widget is.

image

almarklein commented 2 years ago

TBH that snapshot method was a bit of a whim, but I think it can be a really nice feature. E.g. create a notebook with 3D data, manually position the camera to show something specific, then snapshot it, save the notebook, and anyone who views it can see what you meant to show :)

almarklein commented 2 years ago

Thanks for clarifying. I do hope that everyone (including people with Jupyter experience) expect errors to be shown by default. Jupyter does show errors by default, but in our situation this was inconsistent; depending on certain conditions, the errors could be or could not be shown. We fixed that inconsistency with the capturing at the cost of always showing errors in the output.

If we would make it optional to apply the outputcontext, we'd be back to inconsistent behavior. So if we'd go forward with a way to hide errors for cases like dashboards, we should silence all errors. Probably by capturing them like we do now, but then simply not showing them.

djhoese commented 2 years ago

Sounds good. Feel free to merge.