I would like to create a button that when I click it it evaluates a cell containing a manipulate code. Also, I would like another button that when I click the output of manipulate disappears.

How can I do it ?


The first button you don't have to create ;-) It's called the "Enter" button and it's already on your keyboard. Press it with the insertion cursor in the following block of code:

d = Manipulate[Plot[Sin[k x], {x, 0, 2 \[Pi]}], {k, 1, 10}];
e = True;

Dynamic[If[e, d, ""]]

Mathematica graphics

The second button is generated below. Pressing it toggles the Manipulate between an on and off state.

Button["Manipulate On/Off", e = Not[e]]

Mathematica graphics

|improve this answer|||||
  • $\begingroup$ Thanks, it works well in a notebook, but what about use it as a standalone cdf ? It appear doesn't work.... $\endgroup$ – maxmc Mar 16 '12 at 19:40
  • $\begingroup$ Nice, but it evaluates the Manipulate again when you turn it on, as opposed to simply making it disappear and reappear (like if you deleted the manipulate and immediately undid it). $\endgroup$ – rm -rf Mar 16 '12 at 19:58
  • $\begingroup$ R.M it is possible to paste the manipulate box in the Dynamic function (replacing the variable d). As far as I know there is no Visible->False option for a Manipulate; that would have been useful here. Another option would be to have the function in the Manipulate body to be replaced by a Null function depending on the button state. $\endgroup$ – Sjoerd C. de Vries Mar 16 '12 at 20:15
  • 2
    $\begingroup$ @maxmc The manual states about CDF's: "All interactive content must be generated with the Manipulate command and may only use mouse-driven elements, such as Slider, Locator, Checkbox, PopupMenu, etc." So, a button outside a Manipulate won't work in a CDF. $\endgroup$ – Sjoerd C. de Vries Mar 16 '12 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.