Function Repository Resource:

UpdateDynamicsTrackedBy

Source Notebook

Manually update any dynamics that are tracking a given symbol

Contributed by: Bradley Ashby

ResourceFunction["UpdateDynamicsTrackedBy"][sym]

manually updates all Dynamic constructs tracking the symbol sym.

ResourceFunction["UpdateDynamicsTrackedBy"]["context`"]

manually updates all dynamics tracking symbols in the specified context.

Details

The sym can be a string or a symbol.
If the symbol’s context is not on $ContextPath, use the full name of the symbol.
This is useful if a symbol is updated without manipulating it directly. This can happen if its value is tied to a file, LocalSymbol, LocalObject, or CloudObject, or if a Dynamic is otherwise not updating and you want to kick the tires a bit.
ResourceFunction["UpdateDynamicsTrackedBy"] returns the list of BoxObject expressions that were updated.

Examples

Basic Examples (2) 

Create a dynamic output of a single symbol:

In[1]:=
time := Now;
Dynamic[time]
Out[2]=

Trigger an update of the dynamic output:

In[3]:=
ResourceFunction["UpdateDynamicsTrackedBy"][time]
Out[3]=

Scope (2) 

Dynamic does not update when narrowly tracking a symbol that gets its value from a LocalObject:

In[4]:=
LocalSymbol["val"] = 15;
val := LocalSymbol["val"];
Dynamic[val, TrackedSymbols :> {val}]
Out[6]=
In[7]:=
LocalSymbol["val"] = 10
Out[7]=

Update it manually:

In[8]:=
ResourceFunction["UpdateDynamicsTrackedBy"][val]
Out[8]=

Use a context to update all related dynamics:

In[9]:=
demo`a := Now;
demo`b := RandomReal[];
Dynamic[demo`a]
Out[10]=
In[11]:=
Dynamic[demo`b]
Out[11]=
In[12]:=
ResourceFunction["UpdateDynamicsTrackedBy"]["demo`"]
Out[12]=

Properties and Relations (1) 

For dynamics relying on UpdateInterval, UpdateDynamicsTrackedBy can be used to update outside the normal schedule:

In[13]:=
datestring := DateString[]
datestring
Out[14]=
In[15]:=
Dynamic[datestring, UpdateInterval -> 20]
Out[17]=
In[18]:=
ResourceFunction["UpdateDynamicsTrackedBy"][datestring]
Out[18]=

Neat Examples (1) 

Update a dynamic with a button inside the dynamic itself:

In[19]:=
clock := Column[{Button["This button last pressed at:", ResourceFunction["UpdateDynamicsTrackedBy"][clock]], ClockGauge[Now], DateString["Date"]}];
Dynamic[clock]
Out[20]=

Possible Issues (1) 

UpdateDynamicsTrackedBy does not work with symbols scoped by Module and DynamicModule:

In[21]:=
DynamicModule[{moduleSymbol},
 moduleSymbol := Now;
 Column[{
   Button["click", ResourceFunction["UpdateDynamicsTrackedBy"][moduleSymbol]],
   Dynamic[moduleSymbol]
   }]
 ]
Out[21]=

Publisher

Bradley Ashby

Version History

  • 1.0.0 – 25 October 2022

Related Resources

License Information