shiny.reactive.invalidate_later#

shiny.reactive.invalidate_later(delay, *, session=<shiny.types.MISSING_TYPE object>)#

Scheduled Invalidation

Schedules the current 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(), 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.

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *
import random

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

def server(input: Inputs, output: Outputs, session: Session):
    @reactive.Effect
    def _():
        reactive.invalidate_later(0.5)
        print("Random int: ", random.randint(0, 10000))

    @output
    @render.ui
    def value():
        reactive.invalidate_later(0.5)
        return "Random int: " + str(random.randint(0, 10000))


app = App(app_ui, server)
Return type

None