0

I'm using papermill to run my input jupyter notebook for different parameters and then export them all to htmls. In my input notebook, I have the following cell, because I need to rerun a cell earlier in the notebook.

from IPython.display import Javascript Javascript("Jupyter.notebook.execute_cells([20])")

This works fine when running the original input notebook by itself, but when running it with papermill it doesn't seem to work. Is there any way to make it work, or alternatively, is there a way in papermill to run only one cell of a notebook (then I could potentially export the data I need to csv and run it a second time with only that cell)?

Thank you very much!

Sarah
  • 1
  • Please don't [cross-post](https://github.com/nteract/papermill/issues/725) without linking to each same post at each location. – Wayne Jun 05 '23 at 12:20
  • I wonder if that approach is going to still work in version 7 of Jupyter Notebook and going forward. Javascript is a lot more restricted by the complexities of the underlying components. Not sure why you cannot just copy the same code to the new cell and run it? Or you can put the code in a script and run it in each cell with something like `%run myscript_for_original_cell_20.py`? You can make it clear in the comments or markdown near that cell what is happening. ==> I'll try to test in the pre-releases available [here](https://github.com/jtpio/notebook) later. – Wayne Jun 05 '23 at 12:26
  • Sorry I'm new here, how do I cross-post? – Sarah Jun 05 '23 at 13:04
  • I'm printing a figure from the cell and exporting to html afterwards, so if I copy the cell to a new cell the figure won't be printed in the right location unfortunately. – Sarah Jun 05 '23 at 13:06
  • Essentially throughout the notebook I'm processing data and printing figures and then want to print an executive summary figure at the beginning of the file, without moving the processing to the top or rerunning the entire notebook (because it takes long). – Sarah Jun 05 '23 at 13:06
  • That makes more sense as to why re-running the code in place won't work that way. I still have to try if that command you are using now works in the new versions. There are ways though to collect output from notebook steps that take significant effort and/or make reports that would be compatible with Papermill. Still I understand you have this way established for your workflow for now and are looking to not transition if you don't have to. If you do cross-post, you link to the places you cross-post. So for example, I linked to your cross-post at GitHub already. You'd do the same to here at GH. – Wayne Jun 05 '23 at 15:08
  • [This link](https://discourse.jupyter.org/t/notebook-7-pre-releases-are-available/16063/2?u=fomightez) to the pre-release of Notebook 7 works better for now for launching via MyBinder. Currently that method doesn't work as written here in your original post. And thus I'm not sure it is even feasible going forward to keep relying on that method and so I'd caution you to pursue more consistent approaches. [ipylab](https://github.com/jtpio/ipylab) has a command called `'notebook:run-cell` but I'm not sure it is equivalent. Ipylab works in JupyterLab for now but not the Notebook version 7 out now. – Wayne Jun 05 '23 at 15:26
  • Some ways you do what you want that would get away from re-running specific cells would be to collect the output using [scrapbook](https://github.com/nteract/scrapbook). And then generate the report as a separate notebook. Or just build in ways run the notebook in-place and re-arrange the intermediate into a report using nbformat. Or build on the use of `capture` or `with io.capture_output() as captured` , see [here](https://stackoverflow.com/q/64572585/8508004) or [here](https://stackoverflow.com/a/70870733/8508004) to run the code first and then use it to make a separate report notebook. – Wayne Jun 05 '23 at 15:47

0 Answers0