Creating Presentations with Jupyter Notebook

Jupyter Notebook can be turned into a slide presentation that is kind of like using Microsoft Powerpoint, except that you can run the slide’s code live! It’s really neat how well it works. The only con in my book is that there isn’t a lot of theming that can be applied to your slides, so they do end up looking a bit plain.

In this article, we will look at two methods of creating a slideshow out of your Jupyter Notebook. The first method is by using Jupyter Notebook’s built-in slideshow capabilities. The second is by using a plug-in called RISE.

Let’s get started!

Note: This article assumes that you already have Jupyter Notebook installed. If you don’t, then you might want to go to their website and learn how to do so.


The first thing we need to do is to create a new Notebook. Once you have that done and running, let’s create three cells so that we can have three slides. Your Notebook should now look like the following:

An empty notebook with 3 cells

Now let’s turn on the “slideshow” tools. Go to the View menu and then click on the Cell Toolbar menu option. You will find a sub-menu in there that is called Slideshow. Choose that. Now your Notebook’s cell should look like this:

An empty slideshow

There are now little comboboxes on the top right of each cell. These widgets give you the following options:

  • Slide
  • Sub-Slide
  • Fragment
  • Skip
  • Notes

You can just create a series of Slides if you like, but you can make the slideshow a bit more interesting by adding Sub-Slides and Fragments. Sub-slides are just slides that are below the previous one while Fragments are basically fragments within the previous slide. As an aside, I have actually never used Fragments myself. Anyway you can also set a slide to Skip, which just allows you to skip a slide or Notes, which are just speaker notes.

Let’s add some text to our first cell. We will add the text “# Hello Slideshow” to it and set the cell type to Markdown. Note the pound sign at the beginning of the text. This will cause the text to be a heading.

In cell two, we can add a simple function. Let’s use the following code:

def double(x):
    print(x * 2)
 
double(4)

For the last cell, we will add the following text:

# The end

Make sure you set that to be a Markdown cell as well. This is what my cells ended up looking like when I was done:

Getting the slideshow ready

To make things simple, just set each of the cell’s individual comboboxes to Slide.

Now we just need to turn it into an actual slideshow. To do that, you will need save your Notebook and shut down the Jupyter Notebook server. Next you will need to run the following command:

jupyter nbconvert slideshow.ipynb --to slides --post serve
Running the slideshow

To navigate your slideshow, you can use your left and right arrow keys or you can use spacebar to go forward and shift_spacebar to go back. This creates a pretty nice and simple slideshow, but it doesn’t allow you to run the cells. For that, we will need to use the RISE plugin!

Getting Started with RISE

Reveal.js – Jupyter/IPython Slideshow Extension (RISE) is a plugin that uses *reveal.js* to make the slideshow run live. What that means is that you will now be able to run your code in the slideshow without exiting the slideshow. The first item that we need to learn about is how to get RISE installed.

Installing rise with conda

If you happen to be an Anaconda user, then this is the method you would use to install RISE:

conda install -c conda-forge rise

This is the easiest method of installing RISE. However most people still use regular CPython, so next we will learn how to use pip!

Installing rise with pip

You can use Python’s pip installer tool to install RISE like this:

pip install RISE

You can also do `python -m pip install RISE` is you want to. Once the package is installed, you have a second step of installing the JS and CSS in the proper places, which requires you to run the following command:

jupyter-nbextension install rise --py --sys-prefix

If you somehow get a version of RISE that is older than 5.3.0, then you would also need to enable the RISE extension in Jupyter. However, I recommend just using the latest version so you don’t have to worry about that.

Using RISE for a SlideShow

Now that we have RISE installed and enabled, let’s re-open the Jupyter Notebook we created earlier. Your Notebook should now look like this:

Adding RISE

You will notice that I circled a new button that was added by RISE to your Notebook. If you mouse over that button you will see that it has a tooltip that appears that says “Enter/Exit RISE Slideshow”. Click it and you should see a slideshow that looks a lot like the previous one. The difference here is that you can actually edit and run all the cells while in the slideshow. Just double-click on the first slide and you should see it transform to the following:

Running with RISE

After you are done editing, press SHIFT+ENTER to run the cell. Here are the primary shortcuts you will need to run the slideshow effectively:

  • SPACEBAR – Goes forward a slide in the slideshow
  • SHIFT+SPACEBAR – Goes back a slide in the slideshow
  • SHIFT+ENTER – Runs the cell on the current slide
  • DOUBLE-CLICK – To edit a Markdown cell

You can view all the Keyboard shortcuts by going to the Help menu when not in Slideshow mode and clicking the Keyboard Shortcuts option. Most if not all of these shortcuts should work inside of a RISE slideshow.

If you want to start the slideshow on a specific cell, just select that cell and then press the Enter Slideshow button.

RISE also works with Notebook widgets. Try creating a new cell with the following code:

from ipywidgets import interact
 
def my_function(x):
    return x
 
# create a slider
interact(my_function, x=20)

Now start the slideshow on that cell and try running the cell (SHIFT+ENTER). You should see something like this:

Using a widget in RISE

You can use RISE to add neat widgets, graphs and other interactive elements to your slideshow that you can edit live to demonstrate concepts to your attendees. It’s really quite fun and I have used RISE personally for presenting intermediate level material in Python to engineers.

RISE also has several different themes that you can apply as will as minimal support for slide transitions. See the documentation for full information.


Wrapping Up

In this chapter we learned about two good methods for creating presentations out of our Jupyter Notebooks. You can use Jupyter directly via their nbconvert tooling to generate a slideshow from the cells in your Notebook. This is nice to have, but I personally like RISE better. It makes the presentations so much more interactive and fun. I highly recommend it. You will find that using Jupyter Notebook for your presentations will make the slides that much more engaging and it is so nice to be able to fix slides during the presentation too!


Related Reading

Print Friendly, PDF & Email