Initialization

Initialization

is an option for notebooks, cells, Dynamic, DynamicModule, Manipulate and related constructs that specifies an expression to be evaluated when the construct is first displayed.

Details

  • The typical usage is Initialization:>expr.
  • Initialization expressions defined in particular cells in a notebook are evaluated when those cells are first made visible, and not necessarily when the notebook is first opened.
  • Initialization expressions are guaranteed to be evaluated exactly once before the contents of the main construct are resolved.
  • An object that is already initialized can be initialized again if it is deleted, then restored as a result of using Undo. If an object is copied and pasted, each pasted copy will initialize again.
  • Initialization expressions may be applied directly to notebooks and cells. Unlike most other option values, the Initialization option of a cell will not inherit any settings applied at the notebook level.

Examples

open allclose all

Basic Examples  (4)

Specify an expression to be evaluated before displaying Dynamic:

DynamicModule:

Manipulate:

For a notebook:

Properties & Relations  (3)

Initialization is guaranteed to only happen once:

Initialization for outer constructs occurs before initialization for inner constructs:

Each time a Dynamic destroys and recreates an initializing construct, the initialization will run again:

Possible Issues  (3)

Loading a package in the initialization does not allow you to use unqualified symbols from that package:

Doing this properly requires loading the package in the Input cell and loading it in an outer initialization:

This function produces a cell indicating the current Initialization setting upon that cell:

Unlike most options, cells do not inherit Initialization from the notebook setting:

Cells still inherit Initialization from named cell styles:

Introduced in 2007
 (6.0)
 |
Updated in 2020
 (12.1)