How to Synchronise Manipulates in Different Cells?
Since j
and i
have to be synchronized with sync
one can add j = sync;
and i = sync;
at the beginning of parent Manipulates
bodies:
DynamicModule[{d = Range[10]},
Manipulate[
j = sync; (*this is triggered when `sync` gets a values from the second M*)
Column[{d[[;; j]], sync}],
{{j, 1}, 1, 10, 1, TrackingFunction -> ((j = sync = #) &)}
],
SaveDefinitions -> True
]
DynamicModule[{d = Range[10, 100, 10]},
Manipulate[
i = sync;
Column[{d[[;; i]], sync}],
{{i, 1}, 1, 10, 1, TrackingFunction -> ((i = sync = #) &)}
],
SaveDefinitions -> True
]
Another approach is to localize the context of the CDF and use LocalizeVariables -> False
in Manipulate
. You have to remember to manually localize controls in the Manipulate
that you don't want to share.
SetOptions[EvaluationNotebook[], CellContext -> Notebook]
DynamicModule[{d = Range[10], offset},
Manipulate[d[[;; j]] + offset,
{{j, 1}, 1, 10, 1}, {offset, 0, 1},
LocalizeVariables -> False],
SaveDefinitions -> True]
DynamicModule[{d = Range[10, 100, 10], offset},
Manipulate[d[[;; j]] + offset,
{{j, 1}, 1, 10, 1}, {offset, 0, 1},
LocalizeVariables -> False],
SaveDefinitions -> True]
I'm not sure which way will be too much trouble, maintaining the TrackingFunctions
(e.g. Kuba's answers) or the scope of variables. Someone on the site once said Manipulate
is a beast (in part because it automatically rewrites your code, which is probably why the OP had trouble). The typical advice here when things get complicated is to abandon Manipulate
and do it all yourself with DynamicModule[]
.