Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interact/Interactive for widget #4960

Merged
merged 24 commits into from Feb 7, 2014
Merged

Conversation

ellisonbg
Copy link
Member

This is a first official go at implementing interact/interactive on top of IPython's widgets. Closes #4883

@jasongrout
Copy link
Member

(reposting comment here---I accidentally put it on the closed PR)

@interact without arguments---will that use the default arguments in the function, or just use python 3 annotations?

It's been incredibly convenient in Sage to have default arguments in a function control the widgets. It's a really useful shortcut. Something like:

def interact_default(f):
    args,defaults = inspect.getargspec(f) # pseudo-code here...I don't remember exactly what getargspec returns
    return interact(f, zip(args,defaults))


def interact(f, **kwargs):
w = interactive(f, **kwargs)
display(w)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match what we'd said, this needs:

f.widget = w
return f

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus we need some cleverness in this function to detect whether it's passed a function or whether it's being used as a decorator factory. IPython.external.decorator may be able to help with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, I don't think the decorator library is helpful in this case.

@takluyver
Copy link
Member

At present, interact won't work as a decorator. I can work on this after lunch unless you're in the middle of working on it, @ellisonbg .

@ellisonbg
Copy link
Member Author

Here is the plan on I going to pursue:

  • First get interactive (the main function) working with *args, annotations
    and default kwargs.
  • Then build the different versions of interact (decorator, etc.)
  • Then tests everything.

But I won't be working on the interact stuff until later tonight. If you
want to submit a PR to my PR with the decorator stuff in place, that would
be great. I was going to work on this later tonight and this weekend -
especially the tests, but would love any help you can provide.

On Fri, Jan 31, 2014 at 11:57 AM, Thomas Kluyver
notifications@github.comwrote:

At present, interact won't work as a decorator. I can work on this after
lunch unless you're in the middle of working on it, @ellisonbghttps://github.com/ellisonbg.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-33836757
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

A next step after an interact decorator is making it possible to have two interacts in a single cell. If there was a way to contain the output of the interact function to a certain div, then you could have, say, two different interacts in two different tabs, where the output for each function would also be shown in the tab.

@ellisonbg
Copy link
Member Author

Unfortunately that would require refactoring the entire way that output
works. We need to think more about how we can suport these usage cases
though (where multiple things want to generate output).

On Fri, Jan 31, 2014 at 2:26 PM, Jason Grout notifications@github.comwrote:

A next step after an interact decorator is making it possible to have two
interacts in a single cell. If there was a way to contain the output of the
interact function to a certain div, then you could have, say, two different
interacts in two different tabs, where the output for each function would
also be shown in the tab.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-33848894
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

+1 (or really, +a lot). We do it in the cell server by setting output handlers, but I'm not really happy with the way we do it. Hopefully we'll have time soon to rewrite how we direct output.

@takluyver
Copy link
Member

@jasongrout : with using the default arguments to generate widgets, are there ever situations where you want to prevent that, so there isn't a widget for every argument? I'm just wondering if we should do it by default, and if there should be some way of overriding the default per function or per arg.

@jasongrout
Copy link
Member

We make the assumption that every argument corresponds to a control. You can use functools.partial to "hide" arguments if you want.

By the way, we also allow some extra parameters to the interact decorator, like layout and location parameters to specify a control layout in several different ways, and a controls parameter to make it easier to create controls programmatically. I'll try to document this, hopefully sometime next week. Currently I don't think there's a very good explanation of all the various parameters. Our code is here, though: https://github.com/sagemath/sagecell/blob/master/interact_sagecell.py#L278

@ellisonbg
Copy link
Member Author

Ok I have implemented support for *args in interact. This was horrible, but I think I got it right. I will be adding lots of tests. For the most part, it should "just work" with all the different variations of *args, **kwargs, annotations, defaults, etc.

I have also added an @annotate decorator for creating Python 3 compatible annotations in Python 2.

Next task is to create the different decorator syntaxes for interact. Getting close.

@ellisonbg
Copy link
Member Author

I have created a new const pseudo-widget, which, when passed to interact simply holds that value constant and doesn't create a widget for it. This is useful if you want to pass an object to the function called by interact that doesn't get a widget, but it still needed by the function. Simple example:

screen shot 2014-02-01 at 10 58 37 pm

@alimanfoo
Copy link

Apologies if this isn't relevant, but I just tried this branch out and found that typing into a text widget clashed with the modal keys, i.e., I couldn't type 'i' or 's' or any other action key.

@ellisonbg
Copy link
Member Author

We are in the process of fixing these various bugs. I would keep pulling
the latest changes, this particular one should already be fixed. If not,
please let us know.

On Tue, Feb 4, 2014 at 7:10 AM, Alistair Miles notifications@github.comwrote:

Apologies if this isn't relevant, but I just tried this branch out and
found that typing into a text widget clashed with the modal keys, i.e., I
couldn't type 'i' or 's' or any other action key.

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-34068002
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@alimanfoo
Copy link

Thanks Brian. I should be pulling from ellisonbg:newinteract right? I'm on
the latest from that branch and that's where I experienced the problem with
modal keys.

On Tue, Feb 4, 2014 at 5:18 PM, Brian E. Granger
notifications@github.comwrote:

We are in the process of fixing these various bugs. I would keep pulling
the latest changes, this particular one should already be fixed. If not,
please let us know.

On Tue, Feb 4, 2014 at 7:10 AM, Alistair Miles <notifications@github.com

wrote:

Apologies if this isn't relevant, but I just tried this branch out and
found that typing into a text widget clashed with the modal keys, i.e., I
couldn't type 'i' or 's' or any other action key.

Reply to this email directly or view it on GitHub<
https://github.com/ipython/ipython/pull/4960#issuecomment-34068002>
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-34083307
.

Alistair Miles
Head of Epidemiological Informatics
Centre for Genomics and Global Health http://cggh.org
The Wellcome Trust Centre for Human Genetics
Roosevelt Drive
Oxford
OX3 7BN
United Kingdom
Web: http://purl.org/net/aliman
Email: alimanfoo@gmail.com
Tel: +44 (0)1865 287721 _new number_

@ellisonbg
Copy link
Member Author

OK, then we probably haven't rebased that branch since the bugs were fixed.
Why don't you wait a few days and check again. This stuff is getting very
heavy development each day right now. We are aware of these issues though
and will make sure they are fixed. Cheers.

On Tue, Feb 4, 2014 at 9:22 AM, Alistair Miles notifications@github.comwrote:

Thanks Brian. I should be pulling from ellisonbg:newinteract right? I'm on
the latest from that branch and that's where I experienced the problem with
modal keys.

On Tue, Feb 4, 2014 at 5:18 PM, Brian E. Granger
notifications@github.comwrote:

We are in the process of fixing these various bugs. I would keep pulling
the latest changes, this particular one should already be fixed. If not,
please let us know.

On Tue, Feb 4, 2014 at 7:10 AM, Alistair Miles <notifications@github.com

wrote:

Apologies if this isn't relevant, but I just tried this branch out and
found that typing into a text widget clashed with the modal keys,
i.e., I
couldn't type 'i' or 's' or any other action key.

Reply to this email directly or view it on GitHub<
https://github.com/ipython/ipython/pull/4960#issuecomment-34068002>
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Reply to this email directly or view it on GitHub<
https://github.com/ipython/ipython/pull/4960#issuecomment-34083307>
.

Alistair Miles
Head of Epidemiological Informatics
Centre for Genomics and Global Health http://cggh.org
The Wellcome Trust Centre for Human Genetics
Roosevelt Drive
Oxford
OX3 7BN
United Kingdom
Web: http://purl.org/net/aliman
Email: alimanfoo@gmail.com
Tel: +44 (0)1865 287721 _new number_

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-34083772
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@ellisonbg ellisonbg added this to the 2.0 milestone Feb 5, 2014
@ellisonbg
Copy link
Member Author

@minrk here is a notebook with different interact calls for different function arguments:

http://nbviewer.ipython.org/gist/ellisonbg/8836810

@minrk
Copy link
Member

minrk commented Feb 6, 2014

excellent, thanks

@ellisonbg
Copy link
Member Author

Also we should set readout=True on the slider widgets created by interact and friends.

ellisonbg and others added 11 commits February 6, 2014 17:06
Also, preserve the order of function parameters from the signature where
possible.

This uses a backport of the Python 3.3 signature machinery that @minrk
found and improved.
This involves a bunch of really complicated logic to handle the
different ways that function parameters can be processed in Python.
Most importantly, this includes support for *args in interact.
@minrk
Copy link
Member

minrk commented Feb 7, 2014

Should have pretty good test coverage of the abbreviations and different call forms now. I just read through the file, and added a test or two for every abbreviation form I could find, including values coming from default values, annotations, and kwargs passed to interact. Various bugs found and fixed while writing the tests.

I also added readout=True, as you recommended. Should readout=True be the default value for these sliders, not just in interact?

@ellisonbg
Copy link
Member Author

Yes, I think readout=True should probably be default.

On Thu, Feb 6, 2014 at 5:14 PM, Min RK notifications@github.com wrote:

Should have pretty good test coverage of the abbreviations and different
call forms now. I just read through the file, and added a test or two for
every abbreviation form I could find, including values coming from default
values, annotations, and kwargs passed to interact. Various bugs found and
fixed while writing the tests.

I also added readout=True, as you recommended. Should readout=True be the
default value for these sliders, not just in interact?

Reply to this email directly or view it on GitHubhttps://github.com//pull/4960#issuecomment-34394907
.

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

If we're making readout=True the default, then (eventually) I think we should support setting the value via the readout. It's really natural to use the slider if you have a rough idea, but then try to change the number if you want to examine a specific case. It works particularly well with float ranges, since the slider will not hit all floating point numbers in the range.

@minrk
Copy link
Member

minrk commented Feb 7, 2014

@jasongrout that makes sense, eventually.

@minrk
Copy link
Member

minrk commented Feb 7, 2014

readout=True is now the default on all sliders, so I removed the redundant assignment in interact.

@minrk
Copy link
Member

minrk commented Feb 7, 2014

What's left for this PR?

@jasongrout
Copy link
Member

I'd like to take a deeper look at it, but won't have time until next week, likely. I suppose any comments I have could be made after it's merged too, of course.

after recent API changes
@minrk
Copy link
Member

minrk commented Feb 7, 2014

Absolutely, we will probably be iterating on this one for the next few months, so no problem continuing discussion after a first pass has been merged.

@ellisonbg
Copy link
Member Author

Great work on this @minrk and @takluyver ! Merging !

ellisonbg added a commit that referenced this pull request Feb 7, 2014
Interact/Interactive for widget
@ellisonbg ellisonbg merged commit d95eee3 into ipython:master Feb 7, 2014
@jasongrout
Copy link
Member

I hope the "next few months" comment doesn't mean that 2.0 will be delayed that long!

@minrk
Copy link
Member

minrk commented Feb 7, 2014

Not at all, I think we are getting pretty close. I mean that cutting 2.0 doesn't mean we stop finding things to improve here.

@ellisonbg ellisonbg deleted the newinteract branch February 8, 2014 19:50
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement interact/interactive for widgets
5 participants