Skip to contents

Folds a trace (from genui_trace(), or the trace reactive returned by genui_server()) through the same validate-and-execute pipeline the model's tool calls use, recreating every instance in a genui_canvas() with id target. Instance ids come back identical because ids are assigned deterministically and never reused. Embedded inputs return at their default values: input state is ephemeral by design and not part of the trace.

Usage

genui_replay(
  trace,
  catalog,
  target,
  data = NULL,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

trace

A trace list, as returned by genui_trace() (already evaluated, not the reactive) or restored via readRDS().

catalog

The genui_catalog() to render with; component names in the trace must exist in it.

target

Module id of the genui_canvas() to rebuild into. Use a canvas of its own, not one already driven by genui_server().

data

Optional reactive (or function) returning the data object, passed to component servers and check() hooks, as in genui_server().

session

The Shiny session (defaults to the current reactive domain).

Value

(Invisibly) a list with reactives trace and instances describing the rebuilt canvas, as in genui_server().

Details

Entries that no longer validate (for example after the catalog changed) are skipped with a warning; the rest of the trace still replays. The target canvas is emptied first, so replaying twice is idempotent.

Examples

note <- genui_component(
  name = "note_card",
  description = "A card showing a short note.",
  args = list(text = "The note text."),
  ui = function(id, args) htmltools::p(args$text)
)
catalog <- genui_catalog(note)
saved_trace <- list(list(
  op = "create",
  id = "c1",
  component = "note_card",
  args = list(text = "Hello")
))
shiny::testServer(
  function(input, output, session) {
    suppressWarnings(genui_replay(saved_trace, catalog, target = "canvas"))
  },
  {
    stopifnot(identical(names(session$returned$instances()), "c1"))
  }
)
#> Loading required package: shiny