Output Function for Displaying reactive objects and values
Usage
sd_output(
id,
type = NULL,
width = "100%",
display = "text",
inline = TRUE,
wrapper = NULL,
...
)Arguments
- id
Character string. A unique identifier for the output element.
- type
Character string. Specifies the type of output corresponding with the question
id. Can be"question","value","label_option","label_question", orNULL.If"question", it will display a question defined in the server. If"value", it will display the value of questionidselected by the respondent. If"label_option", it will display the label of the option for questionidselected by the respondent. If"label_question", it will display thelabelargument value for questionid. Finally, ifNULL, the function behaves likeshiny::uiOutput().- width
Character string. The width of the UI element. Defaults to
"100%".- display
Character string. Specifies the display type for
"value"outputs. Can be"text","verbatim", or"ui". Only used whentype = "value".- inline
Logical. Whether to render the output inline. Defaults to
TRUE.- wrapper
Function. A function to wrap the output. Only used when
type = "value".- ...
Additional arguments passed to the underlying 'shiny' functions or the wrapper function.
Details
The function behaves differently based on the type parameter:
If
typeisNULL, it acts likeshiny::uiOutput().If
typeis"question", it creates a placeholder for a reactive survey question.If
typeis"value", it creates an output to display the value of a survey question, with the display style determined by thedisplayparameter.
Examples
if (interactive()) {
library(surveydown)
# Use sd_output() to display reactive questions or values:
# First, define something in server of app.R:
# server <- function(input, output, session) {
# completion_code <- sd_completion_code(10)
# sd_store_value(completion_code)
# sd_server()
# }
# Then, display in R chunks of survey.qmd:
# Your code is: `r sd_output("completion_code", type = 'value')`
# Find a working directory and start from a template:
sd_create_survey(template = "reactive_questions")
# This creates survey.qmd and app.R - launch the survey using app.R
}
