Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I haven't found an example where I can't get rid of Refresh[]:

In[1]:= Dynamic[DateString[],UpdateInterval->1]
Out[1]= Sat 10 Nov 2012 01:36:34
In[2]:= Dynamic[Refresh[DateString[],UpdateInterval->1]]
Out[2]= Sat 10 Nov 2012 01:36:34
share|improve this question

2 Answers 2

up vote 10 down vote accepted

Let me know if this is not enough, but I'll just quote the docs for now

From the Advanced Dynamic Functionality tutorial:

Nesting Refresh

In the "Refresh" section examples, Refresh is always the outermost function inside Dynamic. You might almost wonder why its options are not simply options to Dynamic. But in fact it is often important to place Refresh as deeply in the expression as possible, especially if it specifies a time-based updating interval.

Consider this example.

DynamicModule[{showclock = True}, {Checkbox[Dynamic[showclock]], 
  Dynamic[If[showclock, Refresh[DateList[], UpdateInterval -> 0.05], 
    "No clock"]]}]

When the checkbox is checked, Refresh is causing frequent updating of the clock, and CPU time is being consumed to keep things up-to-date. When the checkbox is unchecked, however, the Refresh expression is no longer reached by evaluation, the output remains static, and no CPU time is consumed. If Refresh were wrapped around the whole expression inside Dynamic, CPU time would be consumed constantly, even if the clock were not being displayed. The words "No clock" would be constantly refreshed, pointlessly. (This refreshing is not visible; there is no flicker of the screen, but CPU time is being consumed nevertheless.)

share|improve this answer
    
So what's the difference and why just not use Dynamic instead of Refresh? –  Kuba Nov 6 at 13:27
    
@Kuba They are VERY different. Refresh evaluates to nothing, it's just a marker that means "if you get to evaluate this snippet when updating the dynamic, then remember these are the update settings I want". Dynamic is something that doesn't evaluate at all, and it means "if this is going to be displayed in the front end, evaluate the contents before showing trying to reevaluate every time the user is looking at it and the result would change" –  Rojo Nov 6 at 16:24
    
But where's the difference if in the example above you replace Refresh with Dynamic? I know Refresh alone has no point but why to nest Refresh if you just may nest Dynamics? God, sometimes I think I should switch to cycling. –  Kuba Nov 6 at 16:51
    
@Kuba, its a case where you won't see a visual difference but its just a special case. It's not just that Refresh alone has no point. Its that Refresh doesn't affect calculations, its more like a tag, while Dynamic isn't evaluated. For example, if you changed Refresh[DateList[] to 100 Refresh[DateList[], then it would be different to 100 Dynamic[DateList[]. The Dynamic has to make sense as a visual piece of thing on the screen. –  Rojo Nov 6 at 17:36
    
thanks in advance for you comments. I will respond as soon as I have time to focus on them more. –  Kuba Nov 10 at 14:36

Refresh also has a TrackeSymbols option. Consider the case where several dynamic variables are declared in the first argument to DynamicModule but you only want updating to occur on a proper subset of those variables. An example is given at the bottom of the answer I gave to this question.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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