Ask Your Question
1

Interact: getting a slider to change its range

asked 2012-08-06 11:49:11 +0100

anonymous user

Anonymous

How would I get a slider to change its range when the stuff in the input box before it is changed?

Making two interacts somehow doesn't seem to work...

edit retag flag offensive close merge delete

Comments

1

I understand that "sliders that depend on sliders" is a feature that is coming soon. You can see a sample at: http://interact.sagemath.org/node/15. But, it's not in the standard Sage distribution yet.

calc314 gravatar imagecalc314 ( 2012-08-06 17:53:18 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2016-06-18 23:52:52 +0100

Since this functionality has yet to appear explicitly, one solution is to nest interacts. Here's a slider that depends on a slider (live example):

@interact
def _( n=slider(1,10) ):

  @interact
  def _( m=slider(0,n,default=n/2) ):

        show( 'n=', n )
        show( 'm=', m )

And here's a slider that depends on an input box as per the original question (live example):

@interact
def _( n=input_box(10) ):

  @interact
  def _( m=slider(0,n,default=n/2) ):

        show( 'n=', n )
        show( 'm=', m )
edit flag offensive delete link more
0

answered 2021-11-10 17:57:22 +0100

rrogers gravatar image

An alternative; if yon't mind getting your hands dirt (i.e. side effects)
The return is a tuple (master, secondary, secondary limit) The last is just for debugging. An alternative is to not allow the "illegal" selection.

@interact
def myfunc(x=(0,10)): 
    #sage_interactive(myfunc1, y=(0,floor(x/2)))
    pass
@interact
def myfunc1(y=(0,10)):
    return y

def get_value():
    gg=myfunc.widget.children[0].value
    #print('gg= ',gg,' floor= ',floor(gg/2))
    myfunc1.widget.children[0].max=floor(gg/2)
    return myfunc.widget.children[0].value,myfunc1.widget.children[0].value, myfunc1.widget.children[0].max

I left some debugging junk in.
Tip: The secret is to use
f.?
f.children?
f.widget.children?
Often!

`

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-08-06 11:49:11 +0100

Seen: 1,508 times

Last updated: Nov 10 '21