1
$\begingroup$

For long running evaluations in Dynamic it is recommended that SynchronousUpdating -> False be used to prevent time-out. However, when this is used a DynamicModule custom interface does not show that it is busy by not allowing user interaction. The user, having no sign that something is evaluating after they click, can continuously click on an evaluate button and inadvertently queue up many expensive calculations.

Thus my question: How to show that the system is busy while evaluating Dynamic with SynchronousUpdating -> False?

I thought of two approaches:

  1. Set the cursor to busy.
  2. Disable the evaluate button during evaluation.

I tried MouseApperance and CurrentValue for option 1 but did not get very far. My example is below but it gives the "NoOp" cursor at all times. I'm not certain how to proceed with option 2 given my results with option 1.

DynamicModule[{pl, tbl, n = 1},
 Dynamic[Refresh[
   Pause[7];
   pl = Plot[Sin[n w] + n, {w, -5, 5}];
   tbl = TableForm[{{n, Sin[n x] + n}}, 
     TableHeadings -> {None, {"n", "f[n]"}}];
   (*Dynamic@MouseAppearance[*)
   Column[{
     Button["Update", n = n + 1, ImageSize -> Large, 
      Method -> "Queued"],
     Dynamic@pl,
     Dynamic@tbl
     }]
   (*,
   If[CurrentValue["SynchronousEvaluation"]\[Equal]True,"NoOp",
   "Arrow"]]*)
   ,
   TrackedSymbols -> {n}
   ], SynchronousUpdating -> False]
 ,
 SaveDefinitions -> True
 ]

Uncomment the Dynamic@MouseAppearance and the If to see my attempt at this.

The actual module is large with many calculations, plots, and tables produced. The Pause is set at 7 seconds as the timeout is at 5 seconds. Also, in the module the evaluation time will vary depending on the parameters selected.

I am seeking a solution that allows selection of the text/numbers in tables/grids for copy and paste. Also, tooltips from plots/charts should continue to work when not evaluating.

$\endgroup$
1

2 Answers 2

1
$\begingroup$

This is based on Kuba's deleted answer. I agree with his observation that "clearer [the] code the easier to fix". So here is Kuba's code made clearer.

DynamicModule[{pl, tbl, n = 1, x = 45 °, calculation = False, procedure}, 
  Dynamic[MouseAppearance[
    Column[{
      If[calculation, 
        ProgressIndicator[Appearance -> "Percolate"], 
        Button["Update", 
          calculation = True; FinishDynamic[];procedure[]; calculation = False;,
          ImageSize -> Large, Method -> "Queued"]],
      If[ValueQ @ pl, pl, ""],
      If[ValueQ @ tbl, tbl, ""]}],
    If[calculation, "NoOp", "Arrow"]], 
  TrackedSymbols :> {calculation}],
  Initialization :>
    (procedure[] := 
      (Pause[5];
       pl = Plot[Sin[n w] + n, {w, -5, 5}];
       tbl =
         TableForm[{{n, x, Sin[n x] + n}}, 
           TableHeadings -> {None, {"n", "x", "f[n]"}}];))]

output

$\endgroup$
1
  • $\begingroup$ Thanks for this. Also, I realised that you can remove all of the display Ifs by calling the procedure function in Initialization at the end. $\endgroup$
    – Edmund
    Apr 30, 2015 at 0:42
2
$\begingroup$

Here are some relevant stack exchange posts:

Showing "updating..." message while Manipulate is re-evaluating

Show Progressbar after pressing a button

Evaluation indicator for a notebook

Igor

$\endgroup$
1
  • $\begingroup$ These were useful. $\endgroup$
    – Edmund
    Apr 30, 2015 at 0:43

Your Answer

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

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