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

狂风中的少年 提交于 2019-12-06 05:48:32

问题


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?


回答1:


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.




回答2:


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);
});


来源:https://stackoverflow.com/questions/44273643/how-can-i-jump-to-the-cell-currently-being-run-in-a-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!