Jupyter Notebook在打开状态下运行所有​​单元 [英] Jupyter notebook run all cells on open

查看:111
本文介绍了Jupyter Notebook在打开状态下运行所有​​单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jupyter记事本,我正在尝试以某种方式进行设置,以便在打开笔记本时自动运行所有单元格.

I have a Jupyter noteboook and I'm trying to set it up in a way so that all cells are ran automatically when the notebook is opened.

此行为不同于包含小部件的笔记本的保存输出.窗口小部件似乎仅在运行包含它们的单元格时才为我渲染.考虑以下示例:

This behaviour is different from saved output for notebooks which contain widgets. Widgets only seem to get rendered for me when the cells containing them are run. Consider the following example:

from IPython.display import display
from IPython.html.widgets import IntSlider

w = IntSlider()
display(w)

在执行单元格之前不会显示滑块.

The slider is not displayed until the cell is executed.

这可以通过笔记本元数据或配置文件来完成吗?

Is this something that can be accomplished through Notebook Metadata or configuration files?

编辑: https://try.jupyter.org/似乎请执行以下操作:请注意,打开页面时笔记本没有运行,打开时显示输出.

https://try.jupyter.org/ seems to be doing something like this: Notice that the notebooks are not running when you open the page and display output when they are opened.

添加示例.

推荐答案

  1. 将以下代码段粘贴到普通(代码)单元格中,
  2. 执行它(按 [Ctrl + Enter] ),然后
  3. 保存笔记本.
  1. Paste the snippet below in a normal(code) cell,
  2. execute it (hit [Ctrl + Enter]), and
  3. Save the notebook.

下次(重新)加载时, 所有单元都将运行,并且将使用其刷新后的输出保存检查点.

The next time you (re)load it, all cells will run and a checkpoint will be saved with their refreshed outputs.

%%html
<script>
    // AUTORUN ALL CELLS ON NOTEBOOK-LOAD!
    require(
        ['base/js/namespace', 'jquery'], 
        function(jupyter, $) {
            $(jupyter.events).on("kernel_ready.Kernel", function () {
                console.log("Auto-running all cells-below...");
                jupyter.actions.call('jupyter-notebook:run-all-cells-below');
                jupyter.actions.call('jupyter-notebook:save-notebook');
            });
        }
    );
</script>

请注意,如果您清除上述单元格的输出,则必须重复步骤2和3.

Note that if you clear the output of the above cell, you have to repeat steps 2 and 3.

对于可能要实现的目标,您可以考虑以下更合适的解决方案:

You may consider these more appropriate solutions for what you are probably trying to achieve:

  • Jupyer Thebe: embed code-snippets in static pages communicating with ipython-kernels backends.
  • nteract: Build Electron-based applications from notebooks.
  • Dashboards: The "official"efforts to allow to pre-configure a grid of notebook-cell outputs ("dashboards"), package and serve them as standalone web apps.

您可以在这篇文章.

类似的问题已经提出了 其他网站,但在此googlegroup主题中,有人提交了解决方案,小组主持人将其删除了(!),显然是为了保护地球上的生命:-) 所以,要小心!

Similar questions has been asked before in other sites, but in this googlegroup thread, someone submitted a solution, and the group moderator erased it(!), obviously to preserve life on earth :-) So, be careful with it!

这篇关于Jupyter Notebook在打开状态下运行所有​​单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆