IPython-从小部件运行下面的所有单元格 [英] IPython - Run all cells below from a widget

查看:114
本文介绍了IPython-从小部件运行下面的所有单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用多选小部件,以使用户能够从国家列表中进行选择,然后使用一个小部件按钮,当单击该按钮时,它将运行下面的所有单元格.

I'm trying use a multi select widget to enable users to select from a list of countries, and then have a widget button which, when clicked, runs all the cells below.

这将显示列表.

from IPython.display import display
w = widgets.SelectMultiple(

    description="Select up to five countries",
    options=dfCountries['name'].tolist()   
)
display(w)

我想要这样的东西来运行下面的所有单元格:

And I want something like this to run all cells below:

def run_all(button):
    get_ipython().run_cell()

button = widgets.Button(description="Create next input")
button.on_click(run_all)
display(button)

但是我找不到钩子来运行下面的所有单元格

But I can't find the hook to 'run all cells below

谢谢

推荐答案

如果我正确理解,则可以通过js来完成.

If I understood correctly you could do that via js.

请参见以下代码:

from IPython.display import Javascript
Javascript('IPython.notebook.execute_cells_below()')

将执行活动单元格下面的所有单元格,因此对于您而言,按钮可能类似于:

Will execute all the cells below the active cell so for you button it could be something like:

from IPython.display import Javascript, display
from ipywidgets import widgets

def run_all(ev):
    display(Javascript('IPython.notebook.execute_cells_below()'))

button = widgets.Button(description="Create next input")
button.on_click(run_all)
display(button)

让我知道这是否是您所需要的.

Let me know if this is what you need.

这篇关于IPython-从小部件运行下面的所有单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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