Builds the ptr_state object — the translated typed AST (as a
reactiveVal), the runtime result, the per-layer resolved-data caches,
the eval environment, the input-snapshot machinery, and the shared
bindings / draw trigger — used by ptr_server() and the advanced-embedder
accessors (ptr_extract_plot() / ptr_extract_error() /
ptr_extract_code(), ptr_gg_extra()).
Usage
ptr_init_state(
formula,
envir = parent.frame(),
ui_text = NULL,
expr_check = TRUE,
safe_to_remove = character(),
shared = list(),
draw_trigger = NULL,
producer_debounce_ms = NULL,
ns = shiny::NS(NULL),
server_ns = ns,
auto_bind_shared = FALSE,
shared_resolutions = list(),
shared_stage_enabled = list(),
panel_sources = list(),
plots = NULL
)Arguments
- formula
A single formula string with
ggpaintrplaceholders.- envir
Environment used to resolve local data objects.
- ui_text
Optional named list of copy overrides; see
ptr_ui_text()for the full schema and current defaults.- expr_check
Controls formula-level
ppExprvalidation:TRUE(default) applies the built-in denylist + AST walker;FALSEdisables formula-level validation; alistwithdeny_list/allow_listentries customises the formula-level policy. Runtime-typedppExprinput is always screened against the built-in denylist regardless. See the safety chapter of the ggpaintr book (development-version docs): https://willju-wangqian.github.io/ggpaintr-book/safety.html.- safe_to_remove
Character vector of additional function names whose zero-argument calls should be dropped after substitution.
Named list of reactives (one per shared key) supplied by an outer wrapper such as
ptr_app_grid(). Defaults tolist().- draw_trigger
Optional reactive carrying a click counter — a numeric scalar that is
>= 1once its button has been clicked (e.g. the grid app's "Draw all"input$...value). A redraw fires only when the carried value looks clicked; a reactive carrying any other value (a data frame, a timestamp) invalidates the runtime observer but never triggers a draw. To redraw on arbitrary reactive changes (e.g. a reactive pipeline head in the formula), useptr_options(gate_draw = FALSE)live mode instead. Defaults toNULL.- producer_debounce_ms
Optional. Controls the debounce window applied to producer-style placeholder inputs (
ppText,ppNum,ppExpr) before they invalidate downstream consumer caches.NULL(default) enables auto mode: window starts at 0 ms and the runtime flips to 300 ms after three consecutive upstream resolutions exceed 150 ms (and back to 0 after five consecutive resolutions under 80 ms). Pass0to force off forever, or a positive integer to pin a manual window.- ns
A namespace function used for rendered ids (UI side).
- server_ns
A namespace function used for server-side input lookups. Defaults to
ns.If
TRUE, the host (single-plotptr_app()orptr_app_grid()auto-render path) binds shared widgets at host scope. Relaxes the "missing-from-bindings" check inptr_validate_shared_bindings()(the host auto-binds instead).Named list (keyed by raw shared key) of host-computed resolutions for shared data-consumer (
ppVar) widgets, as returned byptr_resolve_shared_consumers(). When an entry is present, the runtime validates that key's selection against the host-resolved upstream (the same data the host picker was built from) instead of the per-layernode$upstream, so a value valid in the host picker is never rejected by one layer's narrower upstream. Defaults tolist()(no host resolutions; per-layer behaviour).Named list (keyed by raw shared key) of reactives, each returning a logical, that toggle the orphan pipeline stages owned by that shared key (as carried in a
ptr_shared_server()bundle). A missing or unset entry leaves the stage enabled. Defaults tolist().- panel_sources
Named list (keyed by source-node id) of reactives, each returning the host-loaded data for a panel-owned shared source (ADR 0023). Populated by the host's
ptr_setup_panel_sources()and threaded through aptr_shared_server()bundle so per-instance binders read the host's primed data (state$panel_sources[[node$id]]) instead of re-wiring their own source UI. Defaults tolist()(single-plot / per-instance context — no panel-owned sources).- plots
Optional list of formula strings for grid contexts. When supplied (typically by
ptr_app_grid()), the validator forsharedbindings cross-checks shared-key references against every plot's placeholder set, so ashared = "..."annotation that exists in plot 2 but not plot 1 still validates. Defaults toNULL(single- plot context — onlyformulais checked).
Details
This is a state container, not a from-scratch reactive-app builder: it
allocates the reactives but does not attach the pipeline / runtime
observers (those live in internal ptr_setup_* helpers wired by
ptr_server()). Reach for ptr_init_state() directly when you want to
drive the typed tree programmatically or exercise ggpaintr under
shiny::testServer(); for a fully wired app use ptr_server().
