如何在Jupyter笔记本中跳转到当前正在运行的单元格?

11

在 Jupyter notebook 中选择 运行所有运行以上所有 或者 运行以下所有 后,如何跳转到当前正在运行的单元格?

2个回答

6
感谢您提供这个想法,Aaron。但它只能在完整运行一次时起作用,因此需要改进以使其更有用。
我已将其扩展为可以在笔记本执行期间多次使用的快捷方式。
请将以下内容添加到~/.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;
    }
});

现在你可以随时按下Alt-I,使笔记本重新将视图聚焦到正在运行的单元格。

接下来,编写一个扩展程序/快捷方式,使当前运行单元格的视图在整个执行期间保持聚焦,这将更好。


这个代码可以找到最后一个使用的单元格吗?如果不行,如何进行调整? - BND
我在这里向Jupyter团队提出了问题(https://github.com/jupyter/notebook/issues/4323),但没有得到回答。 - stason

4

虽然不是特别优雅,但当我需要自定义功能时,我会使用jupyter的custom.js

下面的代码段绑定了按钮的点击事件并选择当前正在执行的单元格。您可以将其放置在~/.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);
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接