Description Usage Arguments Value Examples
View source: R/radioMatrixInput.R
Create a matrix of radio buttons.
1 | 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
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # 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.