✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Reset n_intervals in dcc.Interval

I have code which changes a dropdown menu every x seconds (5/10/20s etc). It does this by cycling through ~20 options.

I added the max_intervals entry for dcc.Interval to correspond with the number of options that are possible. However, when the code reaches the last number option, it stops updating on the interval. Is there a way to reset n_intervals to 0 after it reaches the last option, to cycle through the options again?

I guess that the easiest solution would be to apply a modulus operator rather than resetting n_intervals. That is, remove the max_intervals argument and use

index = n_intervals % 20

Great idea thanks! That seems to work and not inhibit speed etc!

Hi Emil,

I have the same problem in resetting something that increments with n_intervals up to a specified number. It seems your answer is working for the OP. However, I’m not sure where the index parameter is, and how the n_intervals parameter would be used as a variable in its arguments.

Could you, or somebody who knows, please explain how to do this?

Thanks

I am not sure I understand your question. The code should be in the callback? :slight_smile: