Categories
Jupyter lab

How to run all the cells of a Jupyter Lab notebook when opening it

How to install and use the extension ‘jupyterlab-autoplay’, to run and hide cells automatically.

I’ve just release a new Jupyter Lab extension called autoplay, it runs all the cells of a notebook and hides its code when opening it. In this post I will explain how to install and use it.

Installation

This extension is for Jupyter Lab 2. You can install it running jupyter labextension install jupyterlab-autoplay.

How to use

Here is a short video of how the extension works:

The extension runs automatically when opening a notebook. To configure a notebook:

  1. Open a create a new notebook
  2. Setup the notebook for the extension, use the Jupyter Lab command Set notebook autorun config
The autoplay extension commands

A dialog will open and ask you what action should be performed when opening the notebook. Check both options and confirm.

The autoplay configuration dialog
  1. This will edit the notebook’s metadata so you will need to save it to store the configuration.
  2. You can now close the notebook and re-open it to see it being run automatically.

Work with a configured notebook

If you need to edit a notebook that has ran, you can show all the hidden cells by clicking on Show code cells. This won’t affect the notebook settings so no need to go through the configuration again. You can then edit the code, add new cells, etc.

Warnings

Be careful if you’re using this extension, malicious code could be ran and hidden automatically, so make sure you know that your users are not going to open any dodgy notebook…

Links

4 replies on “How to run all the cells of a Jupyter Lab notebook when opening it”

Thanks for getting in touch.
I’ve been building extension for nearly 2 years now, I will be able to help 🙂
I have sent you an email so we can have a chat about your projects.

I tried to use the above extension programmatically but metadata is not having an autoplay key so getting key error for the same. Where we need to put autoplay related key values
“autoplay”: {
“autoRun”: true,
“hideCodeCells”: true
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code