Ask Your Question
2

interact buttons that do stuff, not just selectors

asked 11 years ago

Tom Burke gravatar image

updated 11 years ago

Is there some way to build a interact control button so that, when pressed, a designated action/program is carried out so as to produce a new result to be added to an existing display -- e.g., a button to generate a new random number and add it to an existing list, a button to add another data point to an existing scatter plot, or to eliminate an outlier, etc. An example that I could look at would be enough to get me started.

FWIW, this is what the "Button" gizmo in Mathematica does: "Button[_label_,_action_] represents a button that is labeled with _label_, and evaluates _action_ whenever it is clicked."

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 10 years ago

ndomes gravatar image

An example what you can do to get something like an action button:

status = False

def toggle():
    global status
    status = not status

@interact
def _(action=[toggle]):
    action()
    print status

A second example ( putting 'random_number' as string in the selector list creates a labeled button)

def random_number():
    return random()

@interact
def _(action=selector(['random_number'],buttons=True)):
    action = eval(action) 
    print action()
Preview: (hide)
link
1

answered 11 years ago

kcrisman gravatar image

This isn't currently possible in the sagenb version of interacts, but I believe something like this can be done in the Sage cell version.

Preview: (hide)
link

Comments

Can you point me to an example?

Tom Burke gravatar imageTom Burke ( 11 years ago )

Not right now - they aren't well advertised, and I didn't save the examples I had, unfortunately. https://plus.google.com/117731028519148902379/posts and http://interact.sagemath.org/all-posts are two places that might include them. The lead developer of the Sage cell would have lots but I think he is too busy to read this forum right now :)

kcrisman gravatar imagekcrisman ( 11 years ago )

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: 11 years ago

Seen: 1,099 times

Last updated: Aug 14 '14