Documentation bug introduced in V10 or eralier and persisting through V11.3
It is a documentation bug because the undocumented optimization method by FE makes major assumptions.
The example is not artificial as it is about basic refreshing of Dynamic
object 'on demand'.
trigger = True;
panel[] := DynamicModule[{x}, Framed@Dynamic[x],
Initialization :> (x = RandomReal[])];
Column[{
Button["redo", trigger = ! trigger, Method -> "Queued"],
Dynamic@trigger,
Dynamic[trigger; panel[], TrackedSymbols :> {trigger}],
Dynamic[trigger; {RandomReal[], panel[]}, TrackedSymbols :> {trigger}]
}]
As you can see Dynamic[trigger; panel[], TrackedSymbols :> {trigger}]
is not displayed correctly after button action.
What is weirder, if you check with Echo
, e.g:
Dynamic[Echo@trigger; panel[], TrackedSymbols :> {trigger}]
you will see that trigger
is echoed while the display does not change.
Why does it happen? Is this a bug?
This piece of code shows a use case of updating a Dynamic
on demand, what is the safe way to achieve this in general?
Similar problems with Dynamic
not updating properly:
What is the difference between Dynamic[x] and Dynamic[ h[x] ] for DynamicModule variables?
Why is PaneSelector caching nested Dynamics and how to switch it off?
Dynamic not responding to Refresh TrackedSymbols
reproduced on Win10 V10.4 / V11.2
[CASE:4017880] was created
Dynamic[ trigger; {RandomInteger[], panel[]}, TrackedSymbols :> {trigger} ]
panel only updates whenRandomInteger[]
changes, I assume the same thing happens with yourRandomReal[]
, it's just less likely thatRandomReal[]
isn't different every time. $\endgroup$Random...[]
then compare it to the existing value before deciding whether to update. Which isn't obvious withRandomReal[]
. $\endgroup$panel[]
evaluates always to the same thing andInitialization
is run later. If you change the definition topanel[] := DynamicModule[{x = RandomReal[]},...
it evaluates to something different each time and this time updating works. $\endgroup$