# Running a DynamicModule outside the Notebook containg the DynamicModule

Inspired by the "Using DynamicModule variables outside the DynamicModule", I'd like to have a hands-free approach to invoking a DynamicModule in a newly created Notebook.

DynamicModule[{x = True, nb = CreateDocument[{"hello"}]},
Checkbox[Dynamic[x, (x = #; SetOptions[nb, Visible -> #]) &]]]


Replacing "hello" with a random input cell, we have:

DynamicModule[{x = True, nb = CreateDocument[{Cell["7+12", "Input"]}]},
Checkbox[Dynamic[x, (x = #; SetOptions[nb, Visible -> #]) &]]]


So -- all I need to know how to do is evaluate that cell without having to click on it and press Shift-Enter. I'm a bit of a noob, but if I can evaluate that 12+7, I'm sure I can evaluate the same cell containing an invocation of a DynamicModule. Probably quite easy, I just don't know where to look. But someone does--is it you?

• Answer below ... – M. Robinson Mar 15 '18 at 6:14
• I'm not sure how is your question related to DynamicModule, the more that your answer does not mention it either. – Kuba Mar 15 '18 at 7:13
• I was assuming that what would work for 12+7 would also work for a symbol referencing a DynamicModule. In other words, the question was really about how to evaluate the cell placed in the new notebook document with having to do it by hand (Shift-Enter, et.al.), whatever it's contents were... – M. Robinson Mar 16 '18 at 3:03
• Of course, this does work with a variable which references a DynamicModule. Mine was just too big to post here. Having said that ("it does work"), let me pull back and say "it almost works". The Dynamic module I'm working with has a lot of interace elements in rows, columns, frames, etc... – M. Robinson Mar 16 '18 at 3:03
• Running the DynamicModule in the notebook where it is defined works perfectly, but when using the method discussed here, the interface element positioning is screwed up pretty badly. – M. Robinson Mar 16 '18 at 3:03

nb = CreateDocument[ExpressionCell[12 + 7, "Input"]]; NotebookEvaluate[nb];