POC: Open Jupyter Book Page in JupyterLite (“View executable source”, ish)

As JupyterLite starts starts to finagle its way into Jupyter Book, such as via jupyterlite-sphinx, in which a simple admonition can be used to embed an in-browser executable notebook or live JupyterLab environment:

or via thebe, to provide in-browser execution support for Jupyter Book executable cells (hopefully, soon… [issue, PR]), I thought I’d riff on the jupyterlite-sphinx approach, which drops a jupyterlite disribution in to a Jupyter Book distribution, and see if I could open a Jupyter Book page rendered from a notebook in a RetroLite (JupyterLite notebook) editor. And it seems that a crude proof-of-concept at least wasn’t that hard, cribbing from an earlier example of how to launch a notebook in Deepnote via a PR in executablebooks/sphinx-book-theme. (Things will be so much easier when this is pluggable…)

My attempt is currently at ouseful-PR/sphinx-book-theme/tree/launch-in-jupyterlite and works by adding a new menu option to the launch menu (which can be used to open the source version of the page in Binderhub, or via a specified JupyterHub) that will open the notebook in a retrolite notebook using the retrolite environment that has been added as part of the book distribution:

What this means is you can “View Executable Source” on the Jupyter book page and tinker with it in a JupyterLite notebook editor. At least at first. Because any edits you make to the notebook are:

  • saved to browser storage, so you can keep your changes;
  • not rendered back to the Jupyter book page.

What this means is that the first time you launch the book page into the notebook editor, it does represent the source of the original page, but thereafter any edits mean the two versions differ. If you edit the notebook and then at a later date launch from the book page again, you will see the latest, edited version of the notebook as saved to browser storage.

What this POC throws up, then, is some user issues:

  • it would be handy to know from the notebook page that the version being edited is different to the original version;
  • it would be handy to revert the edited notebook back to the original version;
  • it would be handy to know from the book page that an edited version of the notebook is available;
  • it would be handy to be able to reflow the book page based on the edited notebook version.

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: