Our Mathematica application obtains a group of input files, analyzes them and generates a report in a form of CDF document. The report contains multiple dynamic/interactive graphs and tables. To save the all required data inside the CDF we use Manipulate with SaveDefinitions ->True. When a section containing a dynamic object appears on a screen, an EnableDynamic button also appears on a top-right corner. To interact with the dynamic object, one should first click on the EnableDynamic button.

The problem is that when we try to visually compare two reports (based on two different sets of input files), the dynamic content of the second report overwrites the dynamic content of the first one. This can be avoided if the two CDFs are opened in separate Windows processes. But this is inconvenient and difficult to explain to users.

Is there an approach that solves this problem by, possibly, generating of unique name spaces for each automatically generated CDF report?

The code illustrating the structure of our report generating package is presented below:


StringLength[$InputFileName] >0 && ".m"==StringTake[$InputFileName,-2],
theDirectory = NotebookDirectory[]


folderName = FileNameSplit[theDirectory][[-1]];

data = Import["data.csv"]//Flatten;

interactiveData = Manipulate[
With[{dataToShow = Take[data, lengthToshow]},ListPlot[dataToShow]],
 {{lengthToshow,  Length[data], "length to show"}, 1,     Length[data],1},SaveDefinitions->True];


With[{reportCells = {
Cell["Example Report\nfolder name: "<>folderName,"Title"],

Cell["Interactive Data","Section",CellTags->"Interactive Data"],

With[{reportDocNB = CreateDocument[reportCells,ShowGroupOpener->True]},

{actionsMenu =ActionMenu[Style["Example Report_"<>folderName,Bold],{

"Interactive Data":>{NotebookLocate["Interactive     Data"],FrontEndExecute[{FrontEndToken["SelectionOpenAllGroups"]}]}

SetOptions[reportDocNB,DockedCells->Cell[BoxData[ToBoxes@Row[{" ","   ",actionsMenu}]]]]

NotebookSave[reportDocNB,FileNameJoin[{theDirectory, "Example_Report_"  <>folderName<>".nb"}]];
CDFDeploy[FileNameJoin[{theDirectory, "Example_Report_"    <>folderName<>".cdf"}],reportDocNB];



If this package runs in a directory where data.csv file contains roots of integers it generates a report like this:

enter image description here

If the data.csv file contains second powers of integers the report present the appropriate interactive visualization.

The problem appears when the two cdf documents are opened together. In this case the dynamic content of the first cdf is overwritten by the second one (we see powers instead of roots):

enter image description here

  • 1
    $\begingroup$ Use DynamicModule to scope your variables (probably with UnsavedVariables) or make your CDFs/NBs with CellContext -> Notebook and incorporate $CellContext` as described in: How does $CellContext` work? $\endgroup$ – Kuba Apr 9 '16 at 18:22
  • $\begingroup$ this post gives in depth discussion of a similar case stackoverflow.com/questions/6579644/… it also contains a solution given by LenoidShifrin, where the Manipulate function is redefined so that it automatically gives unique names to variables/symbols An advantage of this solution is that it is 'local' and does not require restructuring of the report generating code I am going to try it.. $\endgroup$ – VladimirKleiner Apr 11 '16 at 15:53
  • $\begingroup$ If that suits you best then consider posting an answer including this method. $\endgroup$ – Kuba Apr 12 '16 at 12:47
  • $\begingroup$ Are you planning to do something here? $\endgroup$ – Kuba Apr 26 '16 at 6:41
  • $\begingroup$ @Kuba, I was traveling and did not have time to verify the proposed solutions. Planning to do it now. Once I have the verified solution I will post it here. $\endgroup$ – VladimirKleiner Apr 30 '16 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.