reflexive @interact controls (control values update)

37 views
Skip to first unread message

Pedro Cruz

unread,
May 8, 2014, 10:39:19 AM5/8/14
to sage-s...@googlegroups.com
Is possible that after user action on interaction control X the function that updates 
the "interact screen" could also update the X control possible values ?

Thank you,

Pedro

William Stein

unread,
May 8, 2014, 12:01:23 PM5/8/14
to sage-support
On Thu, May 8, 2014 at 7:39 AM, Pedro Cruz <pedrocr...@gmail.com> wrote:
> Is possible that after user action on interaction control X the function
> that updates
> the "interact screen" could also update the X control possible values ?

In SageMathCloud, one can do that by deleting the control and
recreating it, e.g., in this one if you change the function, then the
list of buttons changes accordingly:

@interact
def foo(functions=[sin(x)], f=sin(x)):
show(plot(foo.functions))
del foo.functions
foo.functions = [f(x=x), f(x=x^2), f(x=x^3)]

Note that with the above it puts the new control on the bottom, which
is how I designed this, but isn't desirable.

William


> Thank you,
>
> Pedro
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
Screen Shot 2014-05-08 at 9.00.52 AM.png

kcrisman

unread,
May 8, 2014, 2:51:09 PM5/8/14
to sage-s...@googlegroups.com


On Thursday, May 8, 2014 12:01:23 PM UTC-4, William wrote:
On Thu, May 8, 2014 at 7:39 AM, Pedro Cruz <pedrocr...@gmail.com> wrote:
> Is possible that after user action on interaction control X the function
> that updates
> the "interact screen" could also update the X control possible values ?

In SageMathCloud, one can do that by deleting the control and
recreating it, e.g., in this one if you change the function, then the
list of buttons changes accordingly:


Interesting.  It would be great to have a cheat sheet on what new-style interact stuff works on Sage cell versus SMC.  I understand there are some discrepancies in the syntax? 

Jason Grout

unread,
May 9, 2014, 9:11:24 AM5/9/14
to sage-s...@googlegroups.com
On 5/8/14, 11:01, William Stein wrote:
> @interact
> def foo(functions=[sin(x)], f=sin(x)):
> show(plot(foo.functions))
> del foo.functions
> foo.functions = [f(x=x), f(x=x^2), f(x=x^3)]

Here's a corresponding one working in the cell server:
http://sagecell.sagemath.org/?q=ribyjg

@interact
def foo(self, functions=[sin(x)], f=sin(x)):
show(plot(functions))
del self.functions
self.functions = [f(x=x), f(x=x^2), f(x=x^3)]

Here are a few differences I noticed:

1. Instead of making foo available in the namespace of the function
(thereby possibly masking out a global variable foo), we follow the
python object method convention of passing a self argument in as the
first argument of the function. If the first argument of an interact
function does not have a default value, it is considered a 'self'
argument and is assigned a object that represents the interact itself.
This has its own problems, and I'd be interested in people weighing in
on each approach.

2. William has show(plot(foo.functions)). For the cell server,
self.functions is the *index* into the list of functions, rather than
the actual function. Of course, the actual function is available via
the normal interact way of just using the parameter name, functions.
This makes it less ambiguous to set the value of the selector---you just
set an index, rather than setting a value and then having sage try to
guess from the value what the index is.

3. This doesn't affect the above example, but it seems that when you
have functions=[single value], the cell server interacts creates a
single button, rather than a selector. This has implications for what
self.functions returns. I'm not sure if this is a backwards
compatibility thing or a bug in our implementation. It's in the code
that automagically creates controls based on default values.

4. When you click on a selector button that is already selected, the
cell server ignores the click (since it's already selected), while the
cloud processes the click as a new selection.

Thanks,

Jason


Nils Bruin

unread,
May 9, 2014, 12:14:06 PM5/9/14
to sage-s...@googlegroups.com
Hi Jason,

Thank you very much for all the work on SageCell. It's an unbelievably useful tool to make little demonstrations.


On Friday, May 9, 2014 6:11:24 AM UTC-7, Jason Grout wrote:
4. When you click on a selector button that is already selected, the
cell server ignores the click (since it's already selected), while the
cloud processes the click as a new selection.
 
5. (i've tested this in Chrome and Firefox): If you select another button, you do get the plot you've asked for, but the interact is recreated with the first button highlighted. Due to 4., that means you can't get the plot for the first button any more.

Jason Grout

unread,
May 9, 2014, 4:05:23 PM5/9/14
to sage-s...@googlegroups.com
Right---the interact always is recreating that control, which defaults
to the first entry. With a selector, our thinking was that if the item
was already selected, then it didn't need to be selected again. But I
can see where it would be useful to 'select' an already-selected item.
We can make that change, which would bring SMC and sage cell closer
together.

Jason


Nils Bruin

unread,
May 9, 2014, 5:41:53 PM5/9/14
to sage-s...@googlegroups.com
On Friday, May 9, 2014 1:05:23 PM UTC-7, Jason Grout wrote:
Right---the interact always is recreating that control, which defaults
to the first entry.  With a selector, our thinking was that if the item
was already selected, then it didn't need to be selected again. 
But I can see where it would be useful to 'select' an already-selected item.

That would be a workaround, but ideally one would know which option got selected (if any) and then either not delete/recreate the control or recreate the control with the relevant button "selected".
 

Jason Grout

unread,
May 12, 2014, 8:27:21 AM5/12/14
to sage-s...@googlegroups.com
Right. I think you're pointing out a problem with the example interact
William posted, which I agree is not very polished. I'm more interested
in fixing any issues with the underlying interact system which this
rough example exposed, hence the focus of my comment. Am I
understanding you correctly?

Jason



Nils Bruin

unread,
May 12, 2014, 12:46:27 PM5/12/14
to sage-s...@googlegroups.com
On Monday, May 12, 2014 5:27:21 AM UTC-7, Jason Grout wrote:
Right.  I think you're pointing out a problem with the example interact
William posted, which I agree is not very polished.
 
I haven't looked at William's version, only your SageCell translation. I imagine they would suffer from the same problems, though.
Reply all
Reply to author
Forward
0 new messages