I would like to create a set of custom controls that call Manipulate[] and return the value(s) set during the Manipulate session.

I can easily make a version that uses something like:

MyControl[] := Manipulate[...{a, -10,10}, {b,-1,1}]

This works but variables a, b and any additional variables set by Manipulate are global.

Is it possible to do something like this (Return a Dataset with the selected values for a and b when a "Set" button is clicked and Return Null if "Forget" is clicked):

MyControl[]:= Module[ {a, b},
                      Manipulate[...{a, -10, 10}, {b, -1, 1},
                                 Button["Set", Return[Dataset[Association @ {aValue->a, bValue->b}]]],
Button["Forget", Return[]]]]

1 Answer 1


Are you certain that a and b in the first example are Global? In version 10 they do not appear to be:

enter image description here

(The sliders of one Manipulate do not affect those of the other.)

A look at the Cell Expression for one of these shows:

. . . DynamicModuleBox[{$CellContext`a$$ = -3.3999999999999995`, $CellContext`b$$ = 
0.21999999999999997`, . . .] . . .

It would seem that these are already localized with DynamicModule.

  • $\begingroup$ Hi Mr. Wizard - I see them as global because I can see the values of a and b from the notebook that calls MyControl[]. I would like a and b to only be visible as a Dataset returned from MyControl[]. I would like a and b to only have definition inside MyControl[]. $\endgroup$ Commented Sep 3, 2014 at 20:52
  • $\begingroup$ I'm using DynamicModule[...] around my Manipulate[] and all Manipulate[] variables are visible and settable in the notebook calling MyControl[]. I have set LocalizeVariables->True and all variables used by Manipulate are visible and settable from the calling notebook. $\endgroup$ Commented Sep 3, 2014 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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