vimpyter icon indicating copy to clipboard operation
vimpyter copied to clipboard

Automatically update Jupyter on save?

Open josswright opened this issue 7 years ago • 7 comments

Is there any way to have the Jupyter notebook refresh automatically on save? Or even manually via a command?

(Just to add: this is an amazing plugin -- thank you! I've been interacting with Jupyter notebooks more and more in my data analysis work, and had been desperately hoping that someone would make something like this!)

josswright avatar Feb 28 '18 16:02 josswright

You can refresh the web page to see the new content. I've been looking into the ways of automatic refreshing (using xdotool for example) but it seems close to impossible to find tab with Jupyter notebook in your browser. I probably could refresh it ONLY IF last used tab is the notebook, otherwise I think it is a dead end.

Maybe it would be possible using Jupyter's Python API, adding it as an enhancement, no promises though.

szymonmaszke avatar Feb 28 '18 21:02 szymonmaszke

Well, a little relief before update (I'll try to do it for 0.2.0, when the plugin gets more or less to the stable state):

Update notebook cell with keystroke

You can put this .js script in $HOME/.jupyter/custom/keystroke_update.js and use u (IN JUPYTER NOTEBOOK, NOT VIM) to update modified cell.

szymonmaszke avatar Mar 01 '18 16:03 szymonmaszke

That is really sweet man. I think you have achieved something now that nobody has ever done. Vim and good python plotting, all from the vim terminal. I'm gonna try it out.

michaelfresco avatar Mar 02 '18 07:03 michaelfresco

I can't get that javascript too work though.

Still, pressing cmd R to get the browser to reload would be the killer feature. Ideally, all the graphs would render and you get an instant REPL effect.

michaelfresco avatar Mar 02 '18 08:03 michaelfresco

@michaelfresco It is possible to configure Jupyter notebook to answer yes to all popups. First, if you don't have jupyter config ($HOME/.jupyter) issue the following:

jupyter notebook --generate-config

Now navigate to to $HOME/.jupyter/jupyter_notebook_config.py, find the line #c.JupyterApp.answer_yes=False and change it to c.JupyterApp.answer_yes=True.

The script I provided is just a temporary workaround, not mine, and I can't give any guarantees about it.

szymonmaszke avatar Mar 02 '18 08:03 szymonmaszke

woot woot! - it all works.

Steps I did:

  1. Enabled c.JupyterApp.answer_yes = True in ~/.jupyter/jupyter_notebook_config.py.
  2. I then added this javascript in ~/.jupyter/custom/custom.js.

You should see an alert when reloading, or making a new jupyter notebook.

Okay, it works! Then disable the alert, and press R to run all cells.

alert("hello world")

Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {
    help : 'run all cells',
    help_index : 'zz',
    handler : function (event) {
        IPython.notebook.execute_all_cells();
        return false;
    }}
);

Source script: https://stackoverflow.com/a/40731714/3846189

michaelfresco avatar Mar 02 '18 09:03 michaelfresco

Pretty Amazing Plugin! Looking forward to this new feature! And others too!

Chandlercjy avatar Mar 07 '18 04:03 Chandlercjy