[IPython-dev] Implementing widgets

Ondřej Čertík ondrej.certik@gmail....
Sun Jun 9 23:28:32 CDT 2013


On Sun, Jun 9, 2013 at 10:17 PM, Gabriel Becker <gmbecker@ucdavis.edu> wrote:
> Ondrej,
> This seems very cool.
> I have been working toward what seems like a similar goal, but from a
> different angle.
> My aim is to have the interactivity and ability to control parameter values
> and re-execute the code be an attribute of the codecell itself, rather than
> a consequence of the particular code run within the codecell.
> I approached the problem this way for a couple of reasons:
> My primary focus is on using the notebook as a publication mechanism,
> specifically for publishing computational science and statistical analysis
> based research. Imagine a journal article involving code/output pairs where
> the reader can alter the computations being done (e.g. change the bandwidth
> on a smoothing algorithm) and immediately view the affect that change has on
> the results being discussed.
> It is cleaner to not have the code to render the widget appear in the code
> cell, particularly when the purpose of the widgets for my use case is to
> allow viewers to explore the parameter space without necessarily
> understanding the code or how to modify it.
> Related to the point above, if the interactivity comes from the cells
> themselves, all code used in the analysis itself can be placed within the
> notebook unchanged, rather than needing to be modified to support the
> interactivity (e.g. made into functions which used as callbacks, etc),
> giving a more direct view of exactly what the analyst did.
> For this reason i am working on a interactivecodecell subclass of code cells
> which has associated with it a set of widgets definitions. Each of these
> widget definitions is associated with a variable used by the code. When such
> a cell is rendered, UI components appear above the codeblock. These UI
> widgets then temporarily alter the code to reflect the chosen parameters and
> rerun it to generate fresh output.
> I have a very early proof of concept on github which I can link to if
> desired but its conflated with a bunch of other stuff I'm doing with the
> notebook and isn't in any sort of usable state yet.
> I'd love to hear what people think about these different approaches.

Very interesting. I have a question.

My idea is that the user needs to write a Python function with arguments, like:

def f(a, b, c):

where the arguments "a", "b", "c" have interactive widgets associated
with them. Your idea is that the body
of this function will be in the cell, and then IPython notebook itself
will figure out somehow the arguments "a", "b" and "c" and provide
associated widgets with them?

If you can post a screenshot of how it works, that would be awesome.
It seems to me, that your idea can also be implemented by having a
general traits UI approach. It would only be integrated in the IPython
notebook itself, while in my case, the user actually has to call some
kind of API explicitly (for the better or the worse).


More information about the IPython-dev mailing list