Places a survey inside a larger Shiny application. Pair with
sframe_survey_server() in the server function. The module shows a
welcome screen, the instrument's pages with branching and required-item
checks, and a thank-you screen.
Arguments
- id
A character string. The module namespace ID, passed identically to
sframe_survey_server().- width
Character. CSS width for the survey card. Defaults to
"100%".
Details
Every item type is drawn with the same controls run_survey() uses, so
a response collected through the module has the same columns as one
collected there. sframe_survey_server() describes what is returned.
See also
sframe_survey_server(), run_survey(),
export_survey()
Other Collect functions:
export_google_sheet(),
export_survey(),
sframe_survey_server()
Examples
if (FALSE) { # \dontrun{
library(shiny)
library(surveyframe)
cs <- sframe_choice_set("ag5", 1:5, c("SD", "D", "N", "A", "SA"))
item <- sframe_item("q1", "Rate your experience.", type = "likert",
choice_set = "ag5", required = TRUE)
instr <- sframe_instrument("Quick Survey", components = list(cs, item))
store <- file.path(tempdir(), "responses.csv")
ui <- fluidPage(
sframe_survey_ui("demo"),
verbatimTextOutput("result")
)
server <- function(input, output, session) {
resp <- sframe_survey_server(
"demo", instrument = instr,
# Called before the survey is marked complete. An error here keeps the
# respondent on the last page with a message, so nothing is lost.
on_submit = function(response) {
row <- as.data.frame(response, check.names = FALSE)
utils::write.table(row, store, sep = ",", row.names = FALSE,
col.names = !file.exists(store),
append = file.exists(store))
}
)
output$result <- renderPrint({
req(resp())
resp()
})
}
shinyApp(ui, server)
} # }