Render a SurveyJS form from a JSON schema.
Usage
surveyjs(
schema,
data = NULL,
read_only = FALSE,
live = FALSE,
theme = "DefaultLight",
theme_vars = NULL,
locale = NULL,
pre_render_hook = NULL,
post_render_hook = NULL,
complete_hook = NULL,
width = NULL,
height = NULL,
element_id = NULL
)
Arguments
- schema
List or JSON string; must follow SurveyJS JSON Schema.
- data
Initial values.
- read_only
Render in read-only mode.
- live
Live update responses?
- theme
Theme name.
- theme_vars
Named list of CSS variables (e.g.
--sjs-primary-backcolor
).- locale
Language code (e.g.
"en"
,"de"
)- pre_render_hook
JavaScript code (as a string) to run before rendering the survey. Supply only the body of a JavaScript function — do not wrap it in
function(...) {}
.- post_render_hook
JavaScript code (as a string) to run after the survey is rendered. Also supply only the body of a JavaScript function — not a full
function(...) {}
wrapper.- complete_hook
JavaScript function body to run on survey completion
- width, height
Optional CSS size or number.
- element_id
Optional element ID. Leave NULL in Shiny (it's auto-assigned).
Details
This widget renders a fully customizable survey using SurveyJS v2 inside a Shiny app. It supports themes, read-only mode, initial values, localization, and real-time updates.
Final answers are delivered to input[[paste0(id, "_data")]]
after the user
clicks Complete. If live = TRUE
, updates are delivered to
input[[paste0(id, "_data_live")]]
during input.
The SurveyJS widget is responsive by default. The resize()
method is a placeholder
and does not implement manual resizing logic, as SurveyJS adapts to container size
via CSS flexbox rules.