IPython - Run all cells below from a widget

后端 未结 3 1495
春和景丽
春和景丽 2020-12-25 15:27

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.

<
3条回答
  •  清歌不尽
    2020-12-25 15:46

    If I understood correctly you could do that via js.

    See the following code:

    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.

提交回复
热议问题