reactive.invalidate_later

reactive.invalidate_later(delay, *, session=MISSING)

Scheduled Invalidation

When called from within a reactive context, invalidate_later schedules the reactive context to be invalidated in the given number of seconds.

Parameters

delay: float

The number of seconds to wait before invalidating.

Note

When called within a reactive function (i.e., effect, calc, shiny.render.ui, etc.), that reactive context is invalidated (and re-executes) after the interval has passed. The re-execution will reset the invalidation flag, so in a typical use case, the object will keep re-executing and waiting for the specified interval. It’s possible to stop this cycle by adding conditional logic that prevents the invalidate_later from being run.

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
import random

from shiny import App, Inputs, Outputs, Session, reactive, render, ui

app_ui = ui.page_fluid(ui.output_text("value"))


def server(input: Inputs, output: Outputs, session: Session):
    @render.text
    def value():
        reactive.invalidate_later(0.5)
        return "Random int: " + str(random.randint(0, 10000))


app = App(app_ui, server)