View source: R/input_radioMatrixInput.R
radioMatrixInput | R Documentation |
Create a matrix of radio buttons.
radioMatrixInput(inputId, responseItems, choices, selected = NULL, ...)
inputId |
The input id |
responseItems |
The questions to be asked (row labels) |
choices |
Possible choices (column labels) |
selected |
Initial selected value |
... |
Additional arguments specific to shinysurveys required questions. |
A matrix of radio buttons that can be added to a UI definition. When
run in a Shiny application, this will return NULL
until all possible
response items have been answered, at which time a data frame with the
question_id, question_type, and response, the format used in
getSurveyData
.
# 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Ā® 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) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.