% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plugin-control.R
\name{ctrl_block}
\alias{ctrl_block}
\alias{ctrl_block_server}
\alias{ctrl_block_ui}
\title{Plugin module for external control of block inputs}
\usage{
ctrl_block(server = ctrl_block_server, ui = ctrl_block_ui)

ctrl_block_server(id, x, vars, data, eval)

ctrl_block_ui(id, x)
}
\arguments{
\item{server, ui}{Server/UI for the plugin module}

\item{id}{Namespace ID}

\item{x}{Block}

\item{vars}{Reactive state values (list of \code{reactiveVal} objects keyed by
input name). \code{block_name} is included by the default \code{block_server.block}
even though it is not part of the block's \code{expr_server} state.}

\item{data}{Input data paseed as list of reactive values}

\item{eval}{Reactive that evaluates the block expression against input
data. May be used to validate that the new values produce a successful
evaluation.}
}
\value{
A plugin container inheriting from \code{ctrl_block} is returned by
\code{ctrl_block()}, while the UI component (i.e. \code{ctrl_block_ui()}) is
expected to return shiny UI (i.e. \code{\link[shiny:tagList]{shiny::tagList()}}) and the server
component (i.e. \code{ctrl_block_server()}) is expected to return a value
that passes validation (i.e. \code{TRUE} or a reactive gate).
}
\description{
This plugin enables setting block reactive state values from outside the
block expression server context. Blocks opt in to external control via the
\code{external_ctrl} argument to \code{\link[=new_block]{new_block()}}, which can be set to \code{TRUE} (all
constructor inputs) or a character vector of specific input names. The
default UI renders a \code{\link[shiny:textInput]{shiny::textInput()}} for each externally controllable
input along with a submit \code{\link[shiny:actionButton]{shiny::actionButton()}}. Both the server and UI
can be replaced with custom implementations by passing alternate functions
to \code{ctrl_block()}.
}
\details{
The default server validates submitted values by evaluating the block
expression (via the \code{eval} reactive) after updating state. On success,
a reactive gate is returned as \code{TRUE}, allowing downstream evaluation to
proceed. On failure, state values are reverted to their previous values,
the user is notified, and the gate is set to \code{FALSE}, which blocks
downstream evaluation until a subsequent successful submit.
}
