Have callback perform a different action the first time it runs, vs. every subsequent run

I was developing an app that has a callback that returns A, for the first time it runs, and returns B every time afterward.

The way I was doing this was via having the callback listen to a dcc.Interval object’s n_intervals, and have “A be returned” whenever the conditional if n_intervals == 1 was satisfied (and this would obviously only be satisfied the first time the callback ran).

However, I learned I had to manually reset n_intervals to 0 whenever I set max_intervals to 0 to pause dcc.Interval (because I want to temporarily stop triggering my callback every interval). This has led to some circular Dependency Cycle error, so I can’t do this anymore.

So, essentially I am asking two things that I hope someone can help me with: 1) is there a way to have an interval object’s n_intervals automatically reset to 0, if max_intervals is also, and 2) is there a better way to have a callback run a specific way only once the first time it is run?

Bump. If anyone has a way they get a callback to do something special the first time it runs, I would extremely appreciate any advice on that.

Hi, can’t you simply use store component or hidden div with a flag that is initialized to one value, and used as a state and output of your callback? So very similar to what you did with n_intervals but independent of the interval itself. Since now you have multiple outputs this does not affect the original output of your callback