Automatically refresh notebook on changes

I would like jupyter notebook to monitor the notebook file and automatically reload it in case of changes, without asking.

Yes, I know what I’m doing and that is what I want.

Is that possible?

1 Like

Do you mean reload the notebook if someone else modifies it on disk? Or do you mean re-execute the notebook when it’s modified?

You’ve tagged this topic as JupyterHub, but it sounds like it’s to do with JupyterLab or Jupyter notebook. Which one is it?

Hi!

I open a notebook with the command line jupyter notebook [FILE].

Another software on my PC is going to modify this notebook.

I would like jupyter notebook to get aware that the file changed and reload the notebook. That is, to show on the browser the new file. It already does so if you refresh the page.

I don’t really need this anymore, as I was able to keybind all the steps I have to do (including the browser refresh).

But it would be nice to know whether that is possible nevertheless :slight_smile:

The notebook server doesn’t watch the filesystem for changes, nor is there a mechanism to publish notifications to the UI for something like this. So a lot would have to be implemented (by an extension).

There are also issues with doing it automatically, because discarding a local version and reloading the one from disk is necessarily a data loss event, so should always be done explicitly by the user and not automatically by the system.

1 Like

The notebook server doesn’t watch the filesystem for changes, nor is there a mechanism to publish notifications to the UI for something like this. So a lot would have to be implemented (by an extension).

Thanks, I found a way to “automatically” update it (when I modify the mirrored py file, see below), so I really don’t need this anymore. But it would be a nice feature to have.

But I found a bug where the UI freezes when you refresh the page, I will send another post for that.

There are also issues with doing it automatically, because discarding a local version and reloading the one from disk is necessarily a data loss event, so should always be done explicitly by the user and not automatically by the system.

Again, I know what I am doing.

I have a Python version of the notebook in the “percentage” format, obtained with jupytext. I modify it with Neovim, which is my editor of choice. Then I update the ipynb file.

If there are any difference between the ipynb and the py file, at any point in time, the py file always prevails, and the ipynb should be discarded.

So that is the intended behavior.

1 Like