Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I jump to the cell currently being run in a Jupyter notebook?

After I select run all, run all above, or run all below in a Jupyter notebook, how can I jump to the cell currently being run?

like image 877
Franck Dernoncourt Avatar asked May 30 '17 23:05

Franck Dernoncourt


2 Answers

Thank you for this idea, Aaron. But it works only once on a full run, so it needs to be improved to be more useful.

I have expanded it into a shortcut that can be used many times during the execution of the notebook.

add this to ~/.jupyter/custom/custom.js:

// Go to Running cell shortcut
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('Alt-I', {
    help : 'Go to Running cell',
    help_index : 'zz',
    handler : function (event) {
        setTimeout(function() {
            // Find running cell and click the first one
            if ($('.running').length > 0) {
                //alert("found running cell");
                $('.running')[0].scrollIntoView();
            }}, 250);
        return false;
    }
});

Now you can press Alt-I any time to have the notebook refocus the view on to the running cell.

Next it'd be nice to write an extension/shortcut that keeps the current running cell's view in focus during all of execution.

like image 109
stason Avatar answered Oct 01 '22 07:10

stason


Although not particularly elegant, when I need custom functionality like this I make use of jupyter's custom.js.

The following snippet binds to the buttons' click events and selects the currently executing cell. You can place it in ~/.jupyter/custom/custom.js

$('#run_all_cells, #run_all_cells_above, #run_all_cells_below').click(function() {
    setTimeout(function() {
        // Find running cell and click the first one
        if ($('.running').length > 0) {
            $('.running')[0].click();
        }
    }, 250);
});
like image 28
Aaron Avatar answered Oct 01 '22 07:10

Aaron