How to execute cell in JupyterLab (javascript:Jupyter.notebook.execute_cells not working)

In Jupyter notebook i used the following widget to run a cell after selecting some parameter from some drop down list:

run_html = widgets.Output()
run_html.append_display_data(HTML('<form action="javascript:Jupyter.notebook.execute_cells([5])"><input type="submit" value="Run"></form>'))

widgets.HBox([hely_select, date_tol_select, date_type_select, display_select, run_html, szerkeszt_html])

But it is not working in JupyterLab.

I wonder how can i achieve a same thing under JupyterLab?

I guess this is the code which need to change: javascript:Jupyter.notebook.execute_cells([5])

Thank you

I suspect this is related to this answer.
However, since you are already using ipywidgets, I wonder if there are other ways to achieve something like you want to do without adding in ipylab yet. You can have ipywidgets need something interacted with before it continues to do what it next does when it observes an appropriate change. I wonder if that sort of direction may be compatible with what you need here as it works with more modern Jupyter use.

Thank you very much .
So it is look like this way will not going to work under lab.

Basically this is the workflow for that notebook:

  1. i run all the cell.
  • it is loading pandas table
  • putting up all the dropdown boxes for filtering
  • hiding all the codes
  1. selecting filters from dropdown
  2. push the button (and a nice report will produced)
  3. repeating from step 2. for new report

As a workaround for step 3. i selecting the report area by mouse and pushing the run button just it would much nicer and quicker if i can use the widget button.

All that workflow can be done in an .ipynb file with just ipywidgets and Voila.
Voila/Voici don’t show the code when rendered in the app mode.

Be sure to check out the Voila Gallery for some good representatives.
I pernsonally have made one that is very vaguely of your workflow here (code: here, with more accompanying information here), although that one doesn’t include filters for the data but you do choose what file. Hopefully it is close enough to give you some guidance.


Another option is to not switch to JupyterLab and keep using the older Jupyter Notebook (v6.4 and earlier) with the older server tech, too. However, I’m not sure how much time that will buy you since the server tech has updated to keep in step with JupyterLab and Jupyter Notebook 7+. I suspect NbClassic doesn’t allow Jupyter.notebook.execute_cells() because the server is the one built on newer JpyterLab tech. And of course this is all dependent on you controlling the versions and not updating once it works.

1 Like

Thank you very much,
I will going to use Voila for new dashboards

1 Like