7
$\begingroup$

Why does the following work for Module but not DynamicModule?

Module[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", ProgressIndicator[Dynamic[test]]}]}]]

enter image description here

DynamicModule[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", ProgressIndicator[Dynamic[test]]}]}]]

enter image description here

If I have other reasons to need the module to be a DynamicModule, how can I get this functionality to work?

$\endgroup$
3
  • $\begingroup$ Because of the most annoying bug in UI: 100828, your example is even worse to find a fix for. $\endgroup$
    – Kuba
    Sep 11, 2019 at 18:43
  • 1
    $\begingroup$ In this case Refresh works. $\endgroup$
    – chuy
    Sep 11, 2019 at 18:48
  • $\begingroup$ Wow. Yes, that is an annoying bug, @Kuba! And thank you @chuy, that does indeed work beautifully. $\endgroup$ Sep 11, 2019 at 18:58

1 Answer 1

6
$\begingroup$

Thanks to @chuy, we have a solution:

DynamicModule[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", 
       ProgressIndicator[Dynamic[Refresh[test]]]}]}]]
$\endgroup$
2
  • $\begingroup$ I don't think you need the TrackedSymbols option. $\endgroup$
    – chuy
    Sep 11, 2019 at 19:08
  • $\begingroup$ Ah, thank you! This is my first time to use Refresh, so I didn't even think to leave it out. I'll fix the answer. $\endgroup$ Sep 11, 2019 at 19:21

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.