I want to monitor current results with Dynamic

ls = {}; k = 1;

   AppendTo[ls, k++];
, UpdateInterval -> 10]]

For some reason output updates instantaneously and not every 10 seconds


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 -> {}]

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]]

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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