I think this does what you want. a
is the control variable and x
, y
, and z
are controlled by the togglers.
TogglerBar[
Dynamic[a, (a = #; Clear[x, y, z]; ReleaseHold[#]) &],
{Hold[x = 1] -> 1, Hold[y = 2] -> 2, Hold[z = 3] -> 3}
]
Dynamic[{x, y, z}]
If that does what you want here is a utility function to make using it easier.
SetAttributes[myToggles, HoldFirst]
myToggles[var_, val_] := myToggles[var, val, val]
myToggles[{var__Symbol}, val : {__}, lbl : {__}] :=
Module[{a},
TogglerBar[
Dynamic[a, (a = #; Clear[var]; ReleaseHold[#]) &],
MapThread[
Function[, Hold[# = #2] -> #3, HoldAll],
Unevaluated @ {{var}, val, lbl}
]
]
]
Examples:
myToggles[{a, b, c}, {1, 2, 3}]
Dynamic[{a, b c}]
myToggles[{m, n, o}, {1, 2, 3}, {"one", "two", "three"}]
Dynamic[{m, n, o}]
Dynamic
work for you? E.g.TogglerBar[Dynamic[x,caching_function],choices]
? Thecaching_function
could just set the value passed to a variable, as you wanted. $\endgroup$