Skip to contents

Create a batch reactive that collects payloads and processes them in groups

Usage

payload_batch(
  path = "/ingress",
  session,
  batch_size = 10,
  batch_timeout_ms = 5000,
  process_func = NULL,
  intervalMillis = 500
)

Arguments

path

The URL path used in payload_ui() or payload_methods() (default "/ingress")

session

The Shiny session object

batch_size

Number of payloads to collect before processing (default 10)

batch_timeout_ms

Maximum time to wait for batch completion in ms (default 5000)

process_func

Function to process the batch of payloads

intervalMillis

Polling interval in milliseconds (default 500)

Value

A reactive expression that returns processed batch results

Examples

if (interactive()) {
  server <- function(input, output, session) {
    # Process sensor data in batches of 5
    sensor_batch <- payload_batch("/api/sensors", session,
      batch_size = 5,
      process_func = function(payloads) {
        temperatures <- sapply(payloads, function(p) p$payload$temperature)
        list(
          count = length(temperatures),
          avg_temp = mean(temperatures, na.rm = TRUE),
          max_temp = max(temperatures, na.rm = TRUE),
          timestamp = Sys.time()
        )
      }
    )
  }
}