[IPython-dev] API to execute cells of notebook

Andrew Payne andy at payne.org
Thu Aug 7 13:50:03 EDT 2014


>
> I could do that, but it seems a bit out of place in the IPython widget
> framework.
>
> Imagine if cells had a hidden attribute that could be set in python.  Then
> you could use the widget framework to implement a slideshow, or select
> which type of report to show.  Being able to only access those apis through
> javascript raises the bar for use.
>

The challenge (I suspect) is the execution of a Web notebook is driven from
Javascript.  For example, the execute_all_cells() JS function I referred to
earlier eventually calls notebook.execute_cell(), which invokes the
execute() method on the cell.

For code cells, that generates an execute message to the kernel, see:
https://github.com/ipython/ipython/blob/master/IPython/html/static/notebook/js/codecell.js#L286

And the message:
http://ipython.org/ipython-doc/dev/development/messaging.html#execute

Note that the kernel execute message has the actual code fragment to run,
not a reference to a cell.  The current state of the notebook (e.g. all the
code) is in the browser not the kernel (e.g. you can edit 3 code cells and
then do "run all" and get the result you expect).  This means a "run all"
operation has to involve the browser notebook somehow.

I'm not defending this design or saying what you're looking for is
unreasonable.  I'm just noting that there may be an impedance mismatch with
way the kernel and notebooks are built (which likely derives from the
team's stated design goal to keep them independent).

And given that widgets are essentially a combination of kernel-side Python
and browser-side Javascript with a comm backbone to pass state updates and
messages, you could easily (I think) implement a widget version of what
you're looking for by taking the button widget and calling the
execute_all_cells() method on invocation.

I hope this is helpful,

-andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140807/1056eb63/attachment.html>


More information about the IPython-dev mailing list