% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/paintr-server.R
\name{ptr_extract}
\alias{ptr_extract}
\alias{ptr_extract_plot}
\alias{ptr_extract_error}
\alias{ptr_extract_code}
\title{Extract Runtime Outputs From a \code{ptr_state}}
\usage{
ptr_extract_plot(state)

ptr_extract_error(state)

ptr_extract_code(state)
}
\arguments{
\item{state}{A \code{ptr_state} from \code{\link[=ptr_init_state]{ptr_init_state()}}.}
}
\value{
\code{ptr_extract_plot} returns a \code{ggplot} object (or \code{NULL} on
failure); \code{ptr_extract_error} returns a string or \code{NULL};
\code{ptr_extract_code} returns a single string.
}
\description{
Read the latest plot object, error message, or generated code text from
the runtime result stored on a \code{ptr_state}. Use these to compose custom
UIs or to test the runtime in \code{shiny::testServer}.
}
\section{Reactive contexts}{

Each function wraps its read in \code{\link[shiny:isolate]{shiny::isolate()}}, so it works in both
reactive and non-reactive contexts and returns the current value without
establishing a reactive dependency.

\strong{Do not call these inside a \code{render*{}} block} if you want the output
to update when the plot rerenders. Because \code{isolate()} suppresses the
dependency on \code{state$runtime()}, the render block fires once on mount and
never again. Inside a reactive context, read \code{state$runtime()} directly —
that takes the dependency and re-fires on every \emph{Update plot} click.
Reserve \verb{ptr_extract_*} for non-reactive contexts: download handlers,
\code{\link[shiny:testServer]{shiny::testServer()}} assertions, and one-shot reads outside any session.
}

\examples{
shiny::isolate({
  state <- ptr_init_state(
    "ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()"
  )
  ptr_extract_code(state)
})
}
