reactive.flush

reactive.flush()

Run pending reactive work until the reactive environment is idle.

Runs rounds until the reactive effect queue is empty, every started effect (including its async part) has finished, and each session's resulting outputs have been sent. The wait covers the whole process: other sessions' effects and output flushes too, so steady activity elsewhere delays it.

Warning

Shiny runs reactive work automatically, so an app only needs this to wait for the work that a change from outside the reactive graph causes (such as a value set from another task). It is mostly useful for tests and interactive use.

Note

Called from within an effect, a on_flushed or session.on_flush()/on_flushed() callback, or a task one of these started while it is still running (e.g. via asyncio.create_task() or asyncio.gather()), this returns right away without waiting: that work may be waiting on the caller, so waiting could deadlock. Dependents still run in the next round, but code right after this call can’t rely on them having run yet. A task that outlives the effect that started it (such as an extended task’s body) waits as usual.