Skip to contents

Control how event callbacks are dispatched from the browser to the server.

Usage

event_immediate(fn, coalesce = FALSE, prevent_default = FALSE)

event_throttle(
  fn,
  ms,
  leading = TRUE,
  coalesce = TRUE,
  prevent_default = FALSE
)

event_debounce(fn, ms, coalesce = TRUE, prevent_default = FALSE)

Arguments

fn

An event handler function receiving (event) or (event, id).

coalesce

If TRUE, gate on server idle so events never queue faster than the server can process them. Defaults to FALSE for event_immediate() and TRUE for event_throttle()/event_debounce().

prevent_default

If TRUE, call event.preventDefault() in the browser before dispatching. Defaults to FALSE.

ms

Minimum interval (throttle) or quiet period (debounce) in milliseconds.

leading

If TRUE (default), fire immediately on the first event. If FALSE, wait for the timer before firing.

Value

A wrapped handler.

Details

  • event_immediate(): Fires on every event with no rate limiting. Bare functions passed as event handlers are implicitly wrapped with event_immediate().

  • event_throttle(): Fires at most every ms milliseconds while the event is active.

  • event_debounce(): Waits until the user pauses for ms milliseconds before firing.

The event object

The event argument passed to handlers is a list containing all primitive-valued properties (string, numeric, logical) from the browser event object, plus these element properties:

value

The element's current value (character).

valueAsNumber

Numeric value of the element, or NA if the input is empty or non-numeric (e.g. a blank text box). Useful for range and number inputs.

checked

Logical, for checkbox and radio inputs.

Keyboard events additionally include key, code, ctrlKey, shiftKey, altKey, and metaKey.