14

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)

Markus Gutbrod
  • 141
  • 1
  • 1
  • 5

4 Answers4

16

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

enter image description here

Frâncio Rodrigues
  • 2,190
  • 3
  • 21
  • 30
  • 4
    Yeah, I know that, but I want to do it automatically on certain events (e.g. button clicked) like in https://stackoverflow.com/questions/32714783/ipython-run-all-cells-below-from-a-widget – Markus Gutbrod Nov 08 '18 at 19:39
  • Oh I see...I misunderstood the question. The issue is probably related to the fact that JavaScript execution was limited in JupyterLab(https://github.com/jupyterlab/jupyterlab/issues/3748). Maybe this extension can help you out https://github.com/jupyterlab/jupyterlab/tree/master/packages/javascript-extension – Frâncio Rodrigues Nov 09 '18 at 10:33
  • Humm...It seems they re-enabled javascript execution in v0.33(https://jupyterlab.readthedocs.io/en/stable/getting_started/changelog.html). I am not sure what the issue is then. – Frâncio Rodrigues Nov 09 '18 at 10:38
  • 2
    Is this still an issue? I want to do exactly that, but it seems not possible – Tiago Freitas Pereira Mar 05 '19 at 14:17
  • In the setup explained in my answer, the commando is called "Notebook: Execute Cell and below". I've installed this extension: https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter – Andreas L. Feb 23 '22 at 13:21
1

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

Andreas L.
  • 3,239
  • 5
  • 26
  • 65
1

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)

Sergio Gao
  • 311
  • 3
  • 5
0

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)

Stefan
  • 10,010
  • 7
  • 61
  • 117