I think you should change your setup a little bit.
Including procedures inside Dynamics
is useful somethimes, for better events handling, but nothing fancy is going on here. Thus it is better schedule calculations in a more stable way, by moving the Grid
generation outside Dynamic
.
Your exporting procedure clearly expects myplots
to have an up to date value with respect to expr
.
expr=values;
Export["file.png", myplots];
So keeping myplots=Grid[...]
in a Dynamic
is not a stable solution.
Why it is better to keep "procedures" outside and use Dynamics
only for displaying things?
You can force
FinishDynamic[]
before theExport
but if yourDynamic[myplots...]
is not currently visible on a screen it won't be updated and assigned anyway.ref: "
FinishDynamic[]
does not return until allDynamic
objects are updated and displayed. " - "all" sounds like an overkill for our purpose, doesn't it?Dynamic[ myplots=Grid[...] ]
requests thisGrid
calculation over the PreemptiveLink, it will timeout afterDynamicEvaluationTimeout
(6 seconds by default) and it will freeze other FrontEnd activities till it is finished.
Which isn't critical since you can icrease the timeout limit or use SynchronousUpdating -> False
(runs on the MainLink), but why complicate things.
If something is not clear I'm encouraging you to lookup those symbols in Help and read Advanced Dynamic Functionality tutorial (and related)
What I'd change is the following:
create a plot updating procedure (for flexibility and readability)
updatePlot[]:= (myplots=Grid[...]);
You can put it in DynamicModule's
Initialization
.
insert it in the exporting procedure
expr=values; updatePlot[]; Export["file.png", myplots];
change your
Dynamic
content:Dynamic[expr;myplots, TrackedSymbols:>{expr}]
Notice expr;
, even though it is mentioned in TrackedSymbols
it has to be explicitly stated in Dynamic's
body to be properly tracked.
- additionaly you can introduce progress state variable to show a
ProgressIndicator
instead ofmyPlots
before they are recalculated. Analogously to Palette button with progress barPalette button with progress bar, which is nice from user perspective.