'JupyterLab: Run all cells below

In the Jupyter Notebook I could use the following command to automatically execute all cells below the current cell.

from IPython.display import Javascript
display(Javascript('IPython.notebook.execute_cells_below()'))

However, this doesn't seem to work with JupyterLab. How can I make this work for JupyterLab? (I want to automatically execute all cells below after a button click occured. The original code for this was posted here: IPython - Run all cells below from a widget)



Solution 1:[1]

It is built-in. Click the run menu at the top-left and select "Run Selected Cell and All Below".

enter image description here

Solution 2:[2]

Installing this Jupyter extension in VS-Code, both the commando "Notebook: Execute Cell and Below" and the button in the top-left of each cell are built-in.

The commands can be opened with "CTRL + SHIFT + P".

Commando "Notebook: Execute Cell and Below" jupyter_notebook_execute_cell_and_below_1

Button in the top-left of each cell: jupyter_notebook_execute_cell_and_below_2

Solution 3:[3]

This might be possible with ipylab. However, in JupyterLab 3.2.3 ipylab does not seem to work.

Also see How to cause Jupyter Lab to save notebook (programmatically)

Solution 4:[4]

with ipylab you can run (some) JupyterLab backend commands in frontend, so installing ipylab in jupyter:

import ipywidgets as widgets
app = JupyterFrontEnd()
def run_all(ev):
    app.commands.execute('notebook:run-all-below')

button = widgets.Button(description="Run all below")
button.on_click(run_all)
display(button)

And more, you can create your own Jupyterlab Scripts (Like a matplotlib instruction)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Francio Rodrigues
Solution 2 Andreas L.
Solution 3 Stefan
Solution 4 Sergio Gao