Live online slides with SageMath, Jupyter notebooks, RISE and Binder

Scenario

Viviane is writing slides for a talk; she would like to include live SageMath computations in her slides. She also would like to publish her slides online, letting anyone – during and after her talk – browse the slides and play around with the provided examples.

Note: most of this blog can be adapted for any other computational system that can be run in Jupyter like, for mathematics, GAP, Pari/GP, or Singular.

Some instances

Suggestion of solution

We will use the above slides from the repository https://github.com/nthiery/harmonic-modules as running example.

Components involved

Installation

Install Jupyter’s RISE extension in Sage. From the terminal:

sage -pip install RISE

Notes:

Authoring and showing slides

Open the Jupyter notebook that you want to turn into slides – or create a new one – ; we will assume it’s called talk.ipynb. Activate the Slideshow metadata:

View -> Cell Toolbar -> Slideshow

Choose the role each cell should play: for example start a new slide (Slide), add a fragment to the current slide (Fragment), or don’t show up (Note).

Activate the slideshow by clicking in the corresponding button in the toolbar.

For further details on authoring, showing, and configuring the slideshow, see the RISE documentation.

Publishing the slides on a web page

This assumes that you have access on a web server to publish HTML files that embed javascript.

The slides can be converted to static HTML pages with embedded javascript with:

jupyter nbconvert talk.ipynb --to slides

The produced file talk.slides.html can then be copied to the web server. Readers will be able to see and navigate the slides; however they won’t be able to modify and run the examples.

Publishing live slides on Binder

Add the notebook to a public git repository, for example on github.

Specifying software dependencies

Add metadata to that git repository to specify the software required to run the computations. For SageMath, you can add the following Dockerfile at the root of the repository:

FROM sagemath/sagemath:8.7

# Make sure the contents of the repository is in ${HOME}
COPY --chown=sage:sage . ${HOME}

Specifying additional software dependencies (optional)

The sagemath base docker image contains the required software needed to be compatible with binder. If the notebook uses additional software in addition to SageMath, they need to be specified as well in the Dockerfile. For example, if you are using RISE slides, add this line:

RUN sage -pip install RISE

In general a Python package available from pypi can be installed with:

RUN sage -pip install <package name>

Sage packages can be installed with:

RUN sage -i <package name>

Debian/Ubuntu packages can be installed with:

RUN apt-get update && apt-get install -y <package name>

Hence, to have dot2tex graphics, you would use:

RUN apt-get update && apt-get install -y graphviz
RUN sage -pip install dot2tex

See also the section Preparing your docker file from the binder documentation.

Accessing the notebook in Binder

Go to mybinder.org, specify the address of the git repository (here https://github.com/nthiery/harmonic-modules/ ) and the name of the file (here talk.ipynb`). Click launch, and voilà!

Note: the SageMath docker image is relatively big. Therefore the first time the slides are accessed, or if it has not been accessed in a while, Binder will typically take a couple minutes to launch: it indeed needs to fetch the base SageMath image, build the new image containing the Jupyter extensions and the notebook, and then copy this image around between it’s various machines (that building the image, that storing them, and those running them).

From Binder’s main page, you can get a URL to access directly the live notebook, or even a badge to copy-paste in your web page.

Alternatives

Instead of publishing on Binder, one may author the slides on cocalc, and use its publish feature. (TODO: double check that RISE works on cocalc).

Instead of using a Jupyter notebook, one may author in HTML (or some format that can be converted to HTML), and use ThebeLab or [SageCell][http://sagecell.sagemath.org/]to enable live computations.

Advantages and drawbacks

Traditionally, most mathematicians author their slides using LaTeX+Beamer, and display and publish them in PDF format.

To do

Time and expertise required

Assuming Viviane is familiar with Jupyter, writing her first slides using RISE will take a few minutes and mastering it a few hours.

Assuming Viviane is familiar with version control and Jupyter (basic lab skills taught at Software Carpentry, and the required software required is packaged (conda, debian, docker container, …), the publishing part could take two hours the first time, and minutes later on (typically by having a preconfigured repository where one stores all of one’s presentations)..

What’s new since OpenDreamKit started

OpenDreamKit contribution

SageMath Front Page Jupyter Use Cases Open Science and Reproducibility Best Practice Reproducibility Binder

<