reactive.event
*args, ignore_none=True, ignore_init=False) reactive.event(
Mark a function to react only when an "event" occurs.
Shiny's reactive programming framework is primarily designed for calculated values (calc
) and side-effect-causing actions (effect
) that respond to any of their inputs changing. That's often what is desired in Shiny apps, but not always: sometimes you want to wait for a specific action to be taken from the user, like clicking an input_action_button
, before calculating or taking an action. You do not want the calculation or action to be prematurely triggered if other reactive values that it calls are invalidated. The reactive value (or function) which triggers other calculations or actions in this way is called an event.
These situations demand a more imperative, "event handling" style of programming, which @reactive.event()
provides. It does this by using the isolate
primitive under-the-hood to essentially "limit" the set of reactive dependencies to those in args
. In other words, the event can call as many reactive values as it likes in its code body without taking a reactive dependency on them; it will be invalidated only when a dependency listed in args is invalidated.
Parameters
*args : Callable[[],
object
] | Callable[[], Awaitable[object
]] = ()-
One or more callables that represent the event; most likely this will be a reactive input value linked to a
input_action_button
or similar (e.g.,input.click
), but it can also be a (reactive or non-reactive) function that returns a value. ignore_none : bool = True
-
Whether to ignore the event if the value is
None
or0
. ignore_init : bool = False
-
If
False
, the event triggers on the first run.
Returns
Tip
This decorator must be applied before the relevant reactivity decorator (i.e., @reactive.event
must be applied before @reactive.effect
, @reactive.calc
, @render.ui
, etc).