3
$\begingroup$

I use expressions to create "control panels" to set dynamic variables to control the evaluation of other expressions in a large notebook. For example: enter image description here I would like the expressions that create these grids to hide themselves after evaluation, so I have a cleaner notebook showing controls, but hiding expressions. How can I do this?

$\endgroup$
3
  • $\begingroup$ perhaps use in-place evaluation (Ctrl+Shift+Enter)? $\endgroup$
    – kglr
    Commented Sep 5, 2019 at 16:28
  • $\begingroup$ ... or click the cell bracket of the input cell and uncheck the property Open in Menu >> Cell >> Cell Properties $\endgroup$
    – kglr
    Commented Sep 5, 2019 at 16:35
  • 1
    $\begingroup$ You could add SetOptions[EvaluationCell[], CellOpen -> False] as last command in the cell (to open it, see @kglr's comment). You can also put this code in the CellEpilog option, possibly connected to a custom style, so that you can just set the cell style to make it auto-hide. $\endgroup$
    – Lukas Lang
    Commented Sep 5, 2019 at 16:49

1 Answer 1

4
$\begingroup$

Probably the best what you can do is to collapse the cell group keeping visible only the output cell(s).

If your input cell produces only one output cell, you can define an auxiliary function printAndCollapseInputCell as follows:

printAndCollapseInputCell = 
 Function[CellPrint[ExpressionCell[#, "Output"]]; 
  SelectionMove[EvaluationCell[], Next, "Cell"]; FrontEndTokenExecute["OpenCloseGroup"]];

Now you can apply it to your expression:

printAndCollapseInputCell@Slider[Dynamic[a]]

screenshot1

Or alternatively if your input cell outputs/prints more than one cell, you can define an auxiliary function hideInputCell which should be put at the last (and separate!) line of the input cell:

hideInputCell := (SelectionMove[EvaluationCell[], All, "CellGroup"]; 
  Module[{nb = EvaluationNotebook[], group}, group = NotebookRead[nb]; 
   NotebookWrite[nb, 
    group /. CellGroupData[cells_, ___] :> 
      CellGroupData[cells, Range[2, Length[cells]]]]];)

An example of use:

Print[Slider[Dynamic[a]]]
Slider[Dynamic[a]]

hideInputCell

screenshot2

$\endgroup$
1

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.