I have an app where I’d like a delay in between callbacks. That is, I’d like to respond to a user event by updating a part of the display, waiting 2 seconds, then updating another part of the display.
The best solution I’ve found for this so far is to use a dcc.Interval(): at the time of the first callback I instantiate the Interval, and then when it fires 2 seconds later, I perform the second update. However, only want to make this second update the first time the interval fires, not every 2 seconds, so I’ve got code in my callback along the lines of
if n_intervals==1:
<do stuff and return some updated UI element>
else:
raise Exception() # causes Dash to ignore this callback
The Exception prevents my callback from returning None (or something inappropriate) every 2 seconds after the initial interval has passed.
This means my app, from then on, is raising exceptions every 2 seconds so long as the user doesn’t interact with it. This seems a bit silly. I could set something to destroy the Interval() object after, say, 4 seconds, but I wonder if I’m just taking the wrong approach altogether. Is an Interval() the right way to approach my use-case where for any given user interaction I only want to generate a one-off delay?
Thanks for any advice!