Closed AnnMarieW closed 1 year ago
I updated the component based on your helpful feedback -Thanks!
I made changes to the timer logic to (hopefully) make it less fragile and easier to understand. I'm interested to see if you think it's better.
The only other item, other than testing, is regarding relaxing the constraint that the interval
must be a multiple of duration
. Those questions are inline above.
Moved to dash PR#2352
dcc.Timer()
The new Timer component is a response to the discussion in #857.
dcc.Timer
is based on thedcc.Interval
component. It has all the functionality ofdcc.Interval
plus these new features:countdown
orstopwatch
(count up) modes.timer_format
prop.Component Properties
n_intervals
everyinterval
millisecondsduration
and will show the number of milliseconds remaining. When in stopwatch mode, the timer will count up from zero and show the number of milliseconds elapsed. (read only)countdown
mode and count up from zero instopwatch
modefire_times
can reduce the number of times a callback is fired and can increase app performance. The time(s) must be a multiple of the interval.fire_times
list. Usingat_fire_time
in a callback will trigger the callback at the time(s) infire_times
(Read only)duration
.string
message is to be displayed. Note:timer_format
will overridemessages
.messages
. This formats the timer (milliseconds) into human readable formats.messages
will be shown.Demo
Run
timer_demo_py
to see eight examples usingdcc.Timer
. Some may be good candidates for the docs. Here is a preview:Countdown and Stopwatch timers with messages updated clientside - no callbacks required!
Space shuttle app:
This app uses the
dcc.Timer
component to launch the space shuttle. :rocket:messages
property is used to define the messages that are displayed at certain times during the launch.fire_times
property specifies the time to trigger a callback to start the launch.The timer runs for 51 seconds, but it only fires the callback once (at liftoff) All the other messages are handled clientside by the component.