% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/export_static_survey.R
\name{export_static_survey}
\alias{export_static_survey}
\title{Export a self-contained static HTML survey}
\usage{
export_static_survey(
  instrument,
  output_path = NULL,
  open = interactive(),
  endpoint_url = NULL,
  overwrite = FALSE
)
}
\arguments{
\item{instrument}{An \code{sframe} object.}

\item{output_path}{Character. File path for the output HTML. When \code{NULL},
a \verb{<survey_title>.html} file is written in \code{\link[=tempdir]{tempdir()}}.}

\item{open}{Logical. If \code{TRUE} (default) and the session is interactive,
the file is opened in the default browser after writing.}

\item{endpoint_url}{Character or NULL. A URL to which responses are
POSTed as JSON on submission. When NULL, CSV download is the only
collection mechanism.}

\item{overwrite}{Logical. Whether to overwrite an existing file at
\code{output_path}. Defaults to \code{FALSE}.}
}
\value{
The output path, invisibly.
}
\description{
Generates a single HTML file that presents the survey instrument in a
browser without requiring a Shiny server or any internet connection. All
thirteen item types, branching logic, required-field validation, and
multi-page navigation are handled entirely in client-side JavaScript.
}
\details{
When \code{output_path} is \code{NULL}, the file is written to \code{\link[=tempdir]{tempdir()}}. Supply
an explicit \code{output_path} for any production export that should be kept.

When a respondent clicks the submit button, the browser downloads a
one-row CSV file named \verb{<survey_title>_response_<id>.csv}. If
\code{endpoint_url} is supplied, the same payload is also sent as a JSON
POST request to that URL (for example a Google Apps Script web app or a
serverless function). The two mechanisms are independent: the download
happens regardless, so responses are never lost if the POST fails.

The exported file works offline. It can be hosted on GitHub Pages,
Netlify, any static file server, or e-mailed as an attachment for
opening directly from disk.
}
\examples{
cs    <- sf_choices("ag5", 1:5,
           c("Strongly disagree", "Disagree", "Neutral",
             "Agree", "Strongly agree"))
i1    <- sf_item("sat_1", "Overall I am satisfied with the service.",
                 type = "likert", choice_set = "ag5", required = TRUE)
i2    <- sf_item("comments", "Any additional comments?", type = "textarea")
instr <- sf_instrument("Customer Satisfaction Survey",
                       components = list(cs, i1, i2))

# Write to a temp file without opening the browser
out <- export_static_survey(instr,
                             output_path = file.path(tempdir(), "sat.html"),
                             open = FALSE)
file.exists(out)

\donttest{
# Write to a temp file and open in the default browser
export_static_survey(instr,
                     output_path = file.path(tempdir(), "sat_browser.html"),
                     overwrite = TRUE)

# Write with a Google Apps Script endpoint for server-side collection
export_static_survey(
  instr,
  output_path  = file.path(tempdir(), "sat_endpoint.html"),
  endpoint_url = "https://script.google.com/macros/s/XXXXX/exec",
  open         = FALSE,
  overwrite    = TRUE
)
}
}
\seealso{
\code{\link[=launch_studio]{launch_studio()}}, \code{\link[=launch_builder]{launch_builder()}}, \code{\link[=render_survey]{render_survey()}}
}
