How do I put a Monitor into CDF?

4

1

I would like to keep track of progress of a database request in an Enterprise CDF, but it won't allow PrintTemporary or Monitor[] to add content.

When I use Dynamic[If[progress<1,Refresh[ProgressIndicator@progress,TrackedSymbols:>{progress},UpdateInterval->.5],Histogram[outputData,<various_options_here>]],TrackedSymbols:>{progress}], the ProgressBar doesn't update during VERY heavy operations, like SQLExecute or building a Histogram out of a large set of numbers (2 sets of about 10^6 values). In addition, since the end result of the output has to be without a semicolon, I cannot tag progress=1; onto its end. E.g. progress=0;long_SQL_request;progress=.5;Histogram[huge_data] progress=1; <- obviously can't do that last part. And progress=.5 never gets picked up by the ProgressBar.

Please help. Thank you!

Gregory Klopper

Posted 2013-08-15T23:00:28.243

Reputation: 1 300

are you literally using underscores, e.g. monitor_boxes. – Mike Honeychurch – 2013-08-15T23:34:29.117

no. :-) of course not. That was just a placeholder for general long stuff. – Gregory Klopper – 2013-08-15T23:54:25.343

Why the -1 to this question? It's a valid and complex problem, which I'm sure there's a lot to learn from for people who create CDFs as well those who use DtabaseLink or generate very large time consuming graphics. Ok, enough ranting. Hope someone can actually help me out. – Gregory Klopper – 2013-08-16T00:00:16.697

I do not have a database, but if an operation is blocking, I do not see how a progress bar will update during this time, unless you have a separate scheduled task running on the side. If you can a MWE that does not require database, that shows the problem, I am sure that will help understand more the issue. – Nasser – 2013-08-16T00:13:34.533

that's sort of what I suspect too, but the bigger problem is that a) I cannot display progress AT ALL inside a CDF since it won't create temporary cells in the notebook, and b) since progress bar displays progression through several time consuming elements, I'm ok with not seeing the progress through each, but I'd like to keep moving the progress bar artificially, like in my example. One of the heavy operations is the output, how do I set the progress bar to 1 AFTER the output? – Gregory Klopper – 2013-08-16T00:25:21.887

just got an idea which addresses the sub-question. I can do output=Histogram[...]; progress=1; output That ought to set progress to 100% after the heavy-lifting of Histogram generation is completed and then display the bar chart that is essentially what the product of histogram is. – Gregory Klopper – 2013-08-16T00:27:10.003

Answers

4

Here is an example of using ProgressIndicator. I added Pause[] to simulate some blocking operation, and added Abort button. This is the pattern that I use when using this feature. It is simple and works for me. The idea is to pass the tracking symbol by reference.

Manipulate[(*example using progress monitor in Manipulate*)
 Module[{result},
  abort = False; track=0;
  result = solve[n, Unevaluated[track], Unevaluated[abort]];
  track = 0;
  If[abort, "Aborted", "success!"]],
 Grid[{
   {Control[{{n, 10, "size of problem?"}, 1, 1000, 1, Appearance -> "Labeled"}]},
   {Button["Abort", abort = True, ImageSize -> {40, 30}]},
   {Dynamic[ProgressIndicator[track, {0, 1}]]} }],
 {{track, 0}, None},
 {{abort, False}, None},
 TrackedSymbols :> {n},
 SynchronousUpdating -> False,
 ContinuousAction -> False,
 Initialization :>
  (
   solve[n_, track_, abort_] := Module[{k = 0, result = 1,i},
     Do[PrimeQ[i];
      Pause[0.1];
      k = k + 1;
      track = k/n;
      If[abort, result = -1; Break[]]
      , {i, n}
      ];

     result
     ]
   )
 ]

enter image description here

If you like to see position of progress, it is probably easier to use one of the new version 9 controls such as BulletGauge since those will automatically label the display. Here is example using [BulletGauge][2] and this works without Refresh even, so I removed the passing of the track symbol as in the first example above. I used reference 1 for this example just for now. Help has more information on how to set this control in more specific ways.

Manipulate[
 Module[{result}, abort = False; track = 0;
  result = solve[n]; 
  track = 0;
  If[abort, "Aborted", "success!"]],

 Grid[{{Control[{{n, 10, "size of problem?"}, 1, 1000, 1, Appearance -> "Labeled"}]}, 
     {Button["Abort", abort = True,ImageSize -> {40, 30}]}, 
     {Dynamic[BulletGauge[track, 1, Range[0, 1]]]} (*more options in help*)
   }
  ],     
 {{track, 0}, None},
 {{abort, False}, None},
 TrackedSymbols :> {n},
 SynchronousUpdating -> False,
 ContinuousAction -> False, Initialization :> (

   solve[n_] := Module[{k = 0, result = 1, i},
     Do[PrimeQ[i];
      Pause[0.1];
      k = k + 1;
      track = k/n;
      If[abort, result = -1; Break[]], {i, n}];
     result])
 ]

enter image description here

Nasser

Posted 2013-08-15T23:00:28.243

Reputation: 92 661

1Nasser, that's a GREAT way of showing progress! Just got another idea -- use Join to make it optional: Dynamic[Grid[{{Control[{{n, 10, "size of problem?"}, 1, 1000, 1, Appearance -> "Labeled"}]}, {Button["Abort", abort = True,ImageSize -> {40, 30}]}}~Join~{If[!abort&&0<track<1,{Dynamic[BulletGauge[track, 1, Range[0, 1]]]},{}]}],TrackedSymbols:>{abort,track}] – Gregory Klopper – 2013-08-16T17:54:09.490