WLJS LogoWLJS Notebook

Offload

Wolfram KernelFrontend symbol

Holds an expression to be evaluated on frontend (WLJS)

Offload[expr_, opts___]

It has HoldFirst attribute.

Nested Offload are allowed

Options

"Volatile"

Blocks or allows updates. Only normal evaluation will be allowed if it is set to False. The default values is True

In such case an expression will not be evaluated during the updates and will return undefined value. Use it only in constructions like CompoundExpression

"Static"

Prevents or allows a parent instance to listen changes of an inner expression. The default value is False.

The typical case scenario is you don't want to create extra bondings between an objects and other dynamic symbols.

See also OffloadFromEventObject

Examples

Symbols tracking and deferred evaluation

Typical example for the dynamic evaluation

pts = RandomReal[{-1,1}, {64, 2}];
Graphics[{PointSize[0.02], Point[pts // Offload]}, ImageSize->500]

Now the symbol was actually evaluated on the frontend (browser/ client) using fetched data from the server.

And then, change the variable from a timer

task = SetInterval[With[{},
  pts = (# + 0.001 Sum[
    (i - #)/(Norm[i - #]^3 + 0.1) - (i - #)/(Norm[i - #]^5 + 0.1)
  , {i, pts}]) &/@ pts;
], 100]

Don't forget to remove before you've closed a notebook

TaskRemove[task]

Force WL Kernel to offload an expression

Looking back to the previous example, the function RandomReal implemented on both sides (Kernel and frontend). If you offload it to the Point expression

Graphics[{PointSize[0.02], Point[RandomReal[{-1,1}, {64, 2}] // Offload]}]

Each time you load a notebook the distribution of the point will be different, since it reevaluate it on frontend's side each time.

On this page