jupytext
jupytext copied to clipboard
Auto refresh notebook cell after paired file been modified
right now, when notebook cell changed, the paired file will be auto updated, but not vise versa.
It would be great if jupytext could update the modified cells when paired file been updated, and even auto re run the cell (configurable).
Hello @zhuoqiang , thanks for discussing this.
Right now the synchronisation between the two files only occurs when 1) you save the notebook in Jupyter or 2) you reload the notebook in Jupyter (ipynb is updated in memory only) or 3) you run jupytext --sync. See also https://jupytext.readthedocs.io/en/latest/faq.html#i-have-modified-a-text-file-but-git-reports-no-diff-for-the-paired-ipynb-file
Could you describe how you would see this automatic refresh? Do you want to auto update the .ipynb file on disk, or also trigger a reload in the browser? Or are you viewing the notebook in another program than Jupyter? Also, I'd be curious to know which text editor are you using - does it support scripting?
and even auto re run the cell
Sure we could think of that. Currently there is jupytext --execute if you want to re-run the notebook in full. Running a single cell is more complex because that cell may depend on others. Are you thinking of executing that cell in the current notebook session?
My workflow is like this:
- Edit the paired python file in Emacs
- Refresh the corresponding notebook in browser to get the updated content
- Re run the updated cell
jupytext does a great job to sync and update the notebook file when paired python source file changed, however I still have to do step 2 and step 3 manually.
Ideally, step 2 could be done automatically, that is trigger a reload in jupyter when the paired python file been changed. And step 3 is better to have if possible.
I am also looking for this feature. In addition, is it possible in step 2 to update the text of a cell without trigger a full page reload? After I edit my paired script in vim, I have to switch to browser and trigger a full reload, which show a blank page for 2 seconds to render in my poor Macbook Air.
This could be impossible to achieve in Notebook but JupyterLab might has some advance feature to support this?
Basically I want to use Vim as my editor and Jupyter as my REPL, using Jupytext as the bridge. So I want to minimize the time to complete an iteration of REPL between vim <-> jupytext <-> notebook with the least interruption and keypress as possible.
Hello, yes I agree it would be great to have this auto-refresh. Actually my notebooks also take a long time to refresh, just because they are too heavy... if we found a way to reload only the text version, and do the merge in the brower, that could be way faster.
For this, we would need to 1) find a way to load the input-only version of the notebook and 2) do the merge in TypeScript or Javascript. At the moment, 2) is done with combine.combine_inputs_with_outputs in Python, and I am not sure I'd know how to write that in TS/JS...
I came up with a super hacky approach to this problem and created a Python package. The idea is to run a process that watches for .py file changes and refreshes browser window when they happen. It also uses JS to scroll to changed cell and execute it. I use a browser window spawned with Selenium, but maybe it's possible to do this without it.
Thank you @festeh for sharing this. I will have a look soon!
This package that use jupytext seems to solve this problem: https://github.com/untitled-ai/jupyter_ascending though I haven't tried it yet since I'm not using jupyter anymore.
I've made this vim keybinding that (1) save the python file (2) sync it with the Jupyter notebook (3) shift focus on the browser which contains the notebook (4) refresh the page.
It uses hyperland controller but the concept should be the same whether WM you are using:
nnoremap <C-S> :update <bar> silent !jupytext --sync %<.ipynb; hyprctl dispatch movefocus r; hyprctl dispatch exec ydotool key 63:1 63:0
Also, check out jupynium