jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.1k stars 946 forks source link

Execute all cells after widget interaction #3877

Closed pplonski closed 6 months ago

pplonski commented 6 months ago

Is it possible to execute all cells (or cells below current cell) after interaction with selected widgets? For example, I would like to always re-execute all cells below slider widgets whenever slider is updated.

Is it possible to have such behavior in JupyterLab? is it possible to have Jupyter Lab extension that will re-execute cells after widget interaction?

krassowski commented 6 months ago

Is it possible to have such behavior in JupyterLab? is it possible to have Jupyter Lab extension that will re-execute cells after widget interaction?

Yes, you can either create a custom JupyterLab extension registering a custom slider, with a callback using JupyterLab commands to execute cells directly, or you could execute them from Python via https://github.com/jtpio/ipylab.

Buttons can also use data-commandLinker-command attribute, but I am not sure if these already work with ipywidgets.

pplonski commented 6 months ago

Thank you for prompt response! So it should be possible to add a custom handler to observe widget's changes, and call cells exection from Python code, some pseudo-code below:

slider = ipywidgets.IntSlider(min=-5, max=5, value=1, description='Slider')

def handle_slider_change(change):
    call_notebook_command('notebook:run-all-below')

slider.observe(handle_slider_change, names='value')