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. Can be
"question"
,"value"
, orNULL.
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
type
isNULL
, it acts likeshiny::uiOutput()
.If
type
is"question"
, it creates a placeholder for a reactive survey question.If
type
is"value"
, it creates an output to display the value of a survey question, with the display style determined by thedisplay
parameter.
Examples
if (interactive()) {
library(surveydown)
# Get path to example survey file
survey_path <- system.file("examples", "sd_output.qmd",
package = "surveydown")
# Copy to a temporary directory
temp_dir <- tempdir()
file.copy(survey_path, file.path(temp_dir, "survey.qmd"))
orig_dir <- getwd()
setwd(temp_dir)
# Define a minimal server
server <- function(input, output, session) {
sd_server()
}
# Run the app
shiny::shinyApp(ui = sd_ui(), server = server)
# Clean up
setwd(orig_dir)
}