[IPython-dev] Implementing widgets

Gabriel Becker gmbecker at ucdavis.edu
Mon Jun 10 00:17:36 EDT 2013


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.

Sincerely,
~G


On Sun, Jun 9, 2013 at 2:14 PM, Ondřej Čertík <ondrej.certik at gmail.com>wrote:

> Hi Jake,
>
> Yes. And also the same thing on the JS side --- currently I am
> populating the global name space with global functions, which is not
> good. Ideally there would be some nice javascript class/object and
> then we'll attach the instances into the global IPython object.
>
> Also, this is just a demo of exactly one slider to show that the user
> interface can be a nice simple Python code. I actually need more GUI
> elements. So I think that something like Traits UI:
>
> http://code.enthought.com/projects/traits/docs/html/index.html
>
> would be the way to go.
>
> Those are all questions that the IPython developers should provide
> feedback on, so that I can do something that could be merged.
>
> Ondrej
>
> On Sat, Jun 8, 2013 at 3:43 PM, Jacob Vanderplas
> <jakevdp at cs.washington.edu> wrote:
> > Very cool!
> > One comment: I think that rather than passing python_var an explicit
> name,
> > it might be better to populate a dict in the IPython namespace with the
> > names of objects that need to be accessed by the javascript.  i.e.,
> within
> > the slider init function, you could have something along the lines of:
> >
> > ```
> > import IPython
> > if not hasattr(IPython, "_interactive_elements"):
> >     IPython._interactive_elements = {}
> >
> > key = random.randint(0, 1E7)  # or use some sort of hash function
> > IPython._interactive_elements[key] = self
> > self._python_var = "IPython._interactive_elements[%i]" % key
> > ```
> >
> > That would keep track of the object names in the background.
> > Other than that, I like the implementation!
> >    Jake
> >
> >
> > On Sat, Jun 8, 2013 at 12:25 PM, Ondřej Čertík <ondrej.certik at gmail.com>
> > wrote:
> >>
> >> Hi,
> >>
> >> I have implemented the slider widget here:
> >>
> >> http://nbviewer.ipython.org/5736280
> >>
> >> >From the cell [2] you can see how it is used, it's trivial. I suggest
> >> you run this in your local notebook, because the cell output is not
> >> visible in the nbviewer. Also you need Chrome, as Firefox doesn't
> >> support the HTML 5 slider and I haven't figure out how to use jquery's
> >> slider yet.
> >>
> >> I read your roadmap, and my understanding is that the plan is to start
> >> developing this in December. Unfortunately I needed something now, so
> >> I wrote the above.
> >>
> >> I have already tested it for rotation of a 3D visualization using VTK
> >> 6 in ipython notebook (offscreen rendering) and it works great.
> >>
> >> What is your plan and actual ideas how these widgets should be
> >> implemented?
> >> Is there a reason why work on this cannot start now? I'll be happy to
> >> help with this
> >> and send PRs.
> >>
> >> If I recall correctly, you wanted to implement the widgets using the
> >> IPython implementation of traits?
> >>
> >> Ondrej
> >> _______________________________________________
> >> IPython-dev mailing list
> >> IPython-dev at scipy.org
> >> http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
> >
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev at scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>



-- 
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20130609/7994a593/attachment.html>


More information about the IPython-dev mailing list