nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

Add ability to watch notebook files and convert automatically

Open milliams opened this issue 7 years ago • 6 comments

My use case is using Jupyter Notebooks to create a slideshow. I am then periodically running:

jupyter nbconvert myfile.ipynb --to slides --post serve

This automatically opens a browser tab with the rendered slideshow in it. When I have made a change to the notebook file, I then have to close that browser tab, Ctrl-C on the nbconvert process in the terminal and run it again.

I would like to able able to run something like:

jupyter nbconvert myfile.ipynb --to slides --post serve --watch

which would track changes to the notebook file, automatically rerun the conversion and reload the slideshow in the browser to show the latest changes.

This would mean that I could simply leave that process running in the background while I am developing the material, and only have to deal with switching between the two windows to see the changes almost live.

milliams avatar Jun 08 '18 10:06 milliams

Partial workaround: use entr for reloading. nbconvert doesn't support serving without opening a new browser tab, which means you will have another browser tab opened on each reload.

ls *.ipynb | entr -r jupyter nbconvert myfile.ipynb --to slides --post serve

teodorlu avatar Oct 30 '18 18:10 teodorlu

This can likely be done with Jupyter notebook's post save hooks.

t-makaro avatar Jun 10 '19 04:06 t-makaro

@teodorlu did you find a way to have it not open a new browser tab at each save in the notebook? Thanks 🙏

ssaunier avatar Oct 07 '19 18:10 ssaunier

One can prevent the browser from opening with the following config setting.

c.ServePostProcessor.open_in_browser=False

t-makaro avatar Oct 07 '19 18:10 t-makaro

@t-makaro I put the line in jupyter_notebook_config.py. But the browser continues opening tabs every time a file is saved.

spring-haru avatar Jun 30 '24 07:06 spring-haru

The workaround I came up with that prevents always open a new tab is:

  • open the output (*.slides.html) manually in your browser
  • periodically run nbconvert with watch -n 1 jupyter nbconvert tmp.ipynb --to slides (note: without --post serve) *
  • refresh the page when needed

* (rebuild the slides with entr or similar tools is of course better, but watch is available by default almost every linux distro)

edit: if you use vscode, you can use Live Server to serve the html which will automatically refresh the page if the html has changed. And here you go: a complete automated solution!

turbotimon avatar Jul 05 '24 15:07 turbotimon