szymonmaszke / vimpyter

Edit your Jupyter notebooks in Vim/Neovim
MIT License
333 stars 17 forks source link

Automatically update Jupyter on save? #4

Open josswright opened 6 years ago

josswright commented 6 years ago

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

szymonmaszke commented 6 years ago

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 commented 6 years ago

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.

michaelfresco commented 6 years ago

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 commented 6 years ago

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.

szymonmaszke commented 6 years ago

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

michaelfresco commented 6 years ago

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

Chandlercjy commented 6 years ago

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