shiny.reactive.Effect(fn: Union[Callable[[], None], Callable[[], Awaitable[None]]]) shiny.reactive._reactives.Effect_#
shiny.reactive.Effect(*, suspended: bool = 'False', priority: int = '0', session: Optional[Union[shiny.types.MISSING_TYPE, shiny.session._session.Session]] = 'MISSING') Callable[[Union[Callable[[], None], Callable[[], Awaitable[None]]]], shiny.reactive._reactives.Effect_]

Mark a function as a reactive side effect.

A reactive effect is like a reactive calculation (Calc()) in that it can read reactive values and call reactive calculations, and will automatically re-execute when those dependencies change. But unlike reactive calculations, it doesn’t return a result and can’t be used as an input to other reactive expressions. Thus, observers are only useful for their side effects (for example, performing I/O).

Another contrast between reactive calculations and effects is their execution strategy. Reactive calculations use lazy evaluation; that is, when their dependencies change, they don’t re-execute right away but rather wait until they are called by someone else. Indeed, if they are not called then they will never re-execute. In contrast, effects use eager evaluation; as soon as their dependencies change, they schedule themselves to re-execute.

  • suspended (bool) – If TRUE, start the effect in a suspended state (i.e., it will not execute until resumed and invalidated).

  • priority (int) – The new priority. A higher value means higher priority: an effect with a higher priority value will execute before all effects with lower priority values. Positive, negative, and zero values are allowed.

  • session (Union[MISSING_TYPE, Session, None]) – A Session instance. If not provided, it is inferred via get_current_session().

Return type

A decorator that marks a function as a reactive effect (Effect_).


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

app_ui = ui.page_fluid(ui.input_action_button("btn", "Press me!"))

def server(input: Inputs, output: Outputs, session: Session):
    def _():
            ui.p("Number of clicks: ", input.btn()), selector="#btn", where="afterEnd"

app = App(app_ui, server)