
Create a batch reactive that collects payloads and processes them in groups
Source:R/payload.R
payload_batch.Rd
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)
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()
)
}
)
}
}