12
$\begingroup$

I want to monitor current results with Dynamic

ls = {}; k = 1;

Dynamic[
 Refresh[
   AppendTo[ls, k++];
   Last@ls
, UpdateInterval -> 10]]

For some reason output updates instantaneously and not every 10 seconds

$\endgroup$

3 Answers 3

12
$\begingroup$

When you edit ls, all dynamics that depend on ls will update instantly, this will cause ls to be edited which will update the dynamic which edits ls.... etc.

The way to avoid this is to specify that there should be no tracked symbols:

Dynamic[Refresh[AppendTo[ls, k++];
 Last@ls, UpdateInterval -> 10], TrackedSymbols -> {}]
$\endgroup$
9
$\begingroup$

TrackedSymbols is an option to Refresh, Manipulate, and related functions that specifies which symbols should trigger updates when their values are changed.

Dynamic[Refresh[AppendTo[ls, k++]; Last@ls, TrackedSymbols :> {}, UpdateInterval -> 1]]
$\endgroup$
7
$\begingroup$

UpdateInterval gives an upper bound to the dynamic updates. It doesn't turn off the automatic updating whenever a symbol that is being tracked gets updated.

Your code has AppendTo[ls, sth]. Imagine that as an equivalent of var=Append[ls, sth]; ls=var; where var is just a dummy to show that first Mathematica builds the list and then it assigns it to ls.

In var=Append[ls, sth], ls gets tracked. Then, ls gets changed with ls=var, triggering a self-update.

One possible solution is to make your dynamic NOT track changes in ls, as the other solutions suggested.

Dynamic[Refresh[AppendTo[ls, k++]; Last@ls, None], UpdateInterval -> 2]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.