Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto refresh notebook cell after paired file been modified #406

Open
zhuoqiang opened this issue Dec 23, 2019 · 9 comments
Open

Auto refresh notebook cell after paired file been modified #406

zhuoqiang opened this issue Dec 23, 2019 · 9 comments
Milestone

Comments

@zhuoqiang
Copy link
Contributor

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).

@mwouts
Copy link
Owner

mwouts commented Dec 23, 2019

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?

@zhuoqiang
Copy link
Contributor Author

My workflow is like this:

  1. Edit the paired python file in Emacs
  2. Refresh the corresponding notebook in browser to get the updated content
  3. 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.

@lkhphuc
Copy link

lkhphuc commented Feb 28, 2020

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.

@mwouts
Copy link
Owner

mwouts commented Mar 1, 2020

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...

@festeh
Copy link

festeh commented Sep 20, 2020

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.

@mwouts
Copy link
Owner

mwouts commented Sep 22, 2020

Thank you @festeh for sharing this. I will have a look soon!

@lkhphuc
Copy link

lkhphuc commented Apr 17, 2021

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.

@raffaem
Copy link
Contributor

raffaem commented Nov 21, 2022

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

@raffaem
Copy link
Contributor

raffaem commented Sep 24, 2023

Also, check out jupynium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants