I have a notebook to build a Manipulate
. I perform an evaluation of the notebook and copy & paste the Manipulate
into another notebook that I am using to write the report. I do this several times for different datasets.
What I have found is that all the Manipulate
s switch to the dataset of the last pasted Manipulate
. How can I prevent this from occurring. I was under the impression that Manipulate
kept itself separate from other manipulates as it is basically DynamicModule
underneath.
The Manipulate
has a lot of associated code so I cannot paste it all multiple times into the report notebook. A solution that allows only to copy and paste the output cell is desired.
Minimal example:
data = Range[10];
Manipulate[data[[;; n]], {{n, 1}, 1, 10, 1}, SaveDefinitions -> True]
- Run the above and copy & paste the output cell into a new notebook
- Change
data = Range[10];
todata = Range[10,100,10];
. - Run and copy & paste the output cell below the first pasted output cell in the new notebook.
- Both
Manipulate
s in the new notebook now showRange[10,100,10]
instead of only the second pasted one showing this range.
data = Range[10]; With[{data = data}, Manipulate[data[[;; n]], {{n, 1}, 1, 10, 1}, SaveDefinitions -> True] ]
$\endgroup$DynamicModule[{data = data}, Manipulate[data, {{n, 1}, 1, 10, 1}] ]
p.s. if you copy to the notebook with unique context you don't have to change anything because the definitions contain a reference to$CellContex`data
not aGlobal`
one. $\endgroup$Manipulate
is not correctly (as I understand) scoping its variables. We should not have to resort toWith
? $\endgroup$Manipulate
is not correctly (as I understand) scoping its variables. We should not have to resort toDynamicModule
? $\endgroup$n
).SaveDefinitions
only save others, doesn't localize them additionaly. $\endgroup$