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

share|improve this question
    
are you literally using underscores, e.g. monitor_boxes. –  Mike Honeychurch Aug 15 '13 at 23:34
    
no. :-) of course not. That was just a placeholder for general long stuff. –  Gregory Klopper Aug 15 '13 at 23:54
    
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 Aug 16 '13 at 0:00
    
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 Aug 16 '13 at 0:13
    
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 Aug 16 '13 at 0:25

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
1  
Nasser, 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 Aug 16 '13 at 17:54

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.