I have a DynamicModule
in which I which I wish to start an operation (actually import files) with a button. I would like to monitor the progress with a ProgressIndicator but can't get it to work. This simple example works:
Monitor[
Table[Pause[0.1]; n, {n, 1, 100}],
Dynamic[ProgressIndicator[n, {1, 100}]]
];
I find it interesting that it works even with the final semi-colon. In a DynamicModule
this also works:
ClearAll[test];
test[] := DynamicModule[{},
Row[{Monitor[
Table[Pause[0.1]; n, {n, 1, 100}],
Dynamic[ProgressIndicator[n, {1, 100}]]
];}]
]
test[]
Now I try to put in a button to start and I am lost
ClearAll[test1];
test1[] := DynamicModule[{},
Row[{Button["Start", Monitor[
Table[Pause[0.1]; n, {n, 1, 100}],
Dynamic[ProgressIndicator[n, {1, 100}]]
];]}]
]
test1[]
I have tried several alternatives with no success. I would like the progress indicator to appear in the same row as the button once it has been pressed.
Answer
With small modifications of the code provided by m_goldberg you can get the Button
and the ProgressIndicator
in the same Row
. However, it is always there now and will not appear and disappear.
DynamicModule[{n = 1},
Row[{Button["Start", n = 1;
Do[Pause[0.1]; ++n, {i, 1, 100}], Method -> "Queued"], Spacer[23],
Dynamic[ProgressIndicator[n, {1, 100}]]}]]
In order to get an appearing and disappearing ProgressIndicator
you can use
DynamicModule[{n = 0},
Row[{Button["Start", n = 1;
Do[Pause[0.1]; ++n, {i, 1, 100}], Method -> "Queued"], Spacer[23],
Dynamic@If[n == 0 || n == 101, "", ProgressIndicator[n, {1, 100}]]}]]
Comments
Post a Comment