As shown in the following example, ControlActive does not seem to respond to controls such as SetterBar. Moving the slider resets the value of k, but changing the value of x via SetterBar does not.

Is there some other way to trigger an expensive calculation inside of a Manipulate when some discrete control variable is changed?

 Row[{x, Spacer[10], y, Spacer[10], ControlActive[k = 0, k++]}]
 , {x, {5, 6, 7, 8}, ControlType -> SetterBar}
 , {y, 0, 1}
 , Initialization :> (k = 0)
  • $\begingroup$ I would consider ControlActive a switch and not a trigger. Therefore your question asks two different things, that aren't necessarily related. $\endgroup$
    – Karsten7
    Commented Aug 7, 2015 at 9:41

1 Answer 1


ControlActive doesn't respond to SetterBar, as changing a value using SetterBar doesn't make $ControlActiveSetting being True.

Here is one way to make using the SetterBar reset k:

 Row[{x, Spacer[10], y, Spacer[10], ControlActive[k = 0, k++], Spacer[10], 
 {x, {5, 6, 7, 8}, ControlType -> SetterBar, TrackingFunction -> (x = #; k = 0; &)}, 
 {y, 0, 1}, Initialization :> (k = 0)]
  • $\begingroup$ Great! Am I correct that this can be used generally to trigger an expensive calculation, only when the value of the SetterBar is changed? That would be very useful. $\endgroup$
    – abwatson
    Commented Aug 6, 2015 at 22:19
  • $\begingroup$ @abwatson Yes, it should be. $\endgroup$
    – Karsten7
    Commented Aug 7, 2015 at 9:04
  • $\begingroup$ @abwatson However, there are more ways to manage the evaluations inside a Manipulate. Some of them not suitable for your specific example, where k=0 seems to represents the expansive calculation and k++ the inexpensive one. The example in your question is more about how to set k=0 after clicking on the SetterBar. Your ControlActive just keeps k=0 as long as the Manipulator is used. $\endgroup$
    – Karsten7
    Commented Aug 7, 2015 at 9:48
  • $\begingroup$ What are the other "ways to manage the evaluations inside a Manipulate?" I often have a need to perform an expensive calculation only when one of the control variables is changed. $\endgroup$
    – abwatson
    Commented Aug 7, 2015 at 20:45
  • $\begingroup$ @abwatson For example using Refresh or Dynamic with TrackedSymbols as a second argument. You can find many examples on this site and in the tutorials (e.g. Advanced Manipulate Functionality). $\endgroup$
    – Karsten7
    Commented Aug 7, 2015 at 21:54

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.