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.

One of the original answers was this:

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?

  • $\begingroup$ Answer below ... $\endgroup$ Commented Mar 15, 2018 at 6:14
  • $\begingroup$ I'm not sure how is your question related to DynamicModule, the more that your answer does not mention it either. $\endgroup$
    – Kuba
    Commented Mar 15, 2018 at 7:13
  • $\begingroup$ 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... $\endgroup$ Commented Mar 16, 2018 at 3:03
  • $\begingroup$ 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... $\endgroup$ Commented Mar 16, 2018 at 3:03
  • $\begingroup$ 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. $\endgroup$ Commented Mar 16, 2018 at 3:03

1 Answer 1


I'll answer my own question:

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

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.