In this tutorial, learn how to create a slideshow presentation with Jupyter Notebooks. The open-source web app allows you to run code in your slides live.
Let’s be friends:
Comment ( 0)
Join the DZone community and get the full member experience.
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!
—
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:
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:
For the last cell, we will add the following text:
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:
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!
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.
If you happen to be an Anaconda user, then this is the method you would use to install 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!
You can use Python’s pip installer tool to install RISE like this:
You can also do `python -m pip install RISE` if 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:
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.
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:
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 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:
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 well as minimal support for slide transitions. See the documentation for full information.
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.