# NOT RUN {
# For use as a normal Shiny input:
if (interactive()) {
library(shiny)
ui <- fluidPage(
radioMatrixInput("matInput",
responseItems = c("Love sushi?", "Love chocolate?"),
choices = c("Disagree", "Neutral", "Agree"))
)
server <- function(input, output, session) {
observe({
print(input$matInput)
})
}
shinyApp(ui, server)
}
# For use in {shinysurveys}
if (interactive()) {
df <- data.frame(
question = c(rep("I love sushi.", 3), rep("I love chocolate.",3),
"What's your favorite food?", rep("Goat cheese is the GOAT.", 5),
rep("Yogurt and berries are a great snack.",5),
rep("SunButter<U+00AE> is a fantastic alternative to peanut butter.", 5)),
option = c(rep(c("Disagree", "Neutral", "Agree"), 2), "text",
rep(c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"), 3)),
input_type = c(rep("matrix", 6), "text", rep("matrix", 15)),
# For matrix questions, the IDs should be the same for each question
# but different for each matrix input unit
input_id = c(rep("matId", 6), "favorite_food", rep("matId2", 15)),
dependence = NA,
dependence_value = NA,
required = FALSE
)
library(shiny)
ui <- fluidPage(
surveyOutput(df)
)
server <- function(input, output, session) {
renderSurvey()
observe({
print(input$matId)
print(input$favorite_food)
print(input$matId2)
})
}
shinyApp(ui, server)
}
# }
Run the code above in your browser using DataLab