rateUI | R Documentation |
User interface builder for likert scale tasks
rateUI(
id = "rate",
type = c("button", "slider"),
align = "center",
n_scales = 1,
scaleFillCol = "white",
scaleTextCol = "black",
scaleTextSz = "16px"
)
id |
The id of the module. Must be the same as the ID of |
type |
One of 'button' or 'slider'. Which type of input will the respondents give? Must be the same as in the corresponding call to |
align |
One of 'left', 'center', or 'right'. Should the elements in this UI be left-, center-, or right-aligned? |
n_scales |
Integer. How many scales should be displayed in the interface? Must be the same value as in the corresponding call to |
scaleFillCol |
A valid hexidecimal code or color name for the scale background. Defaults to white. |
scaleTextCol |
A valid hexidecimal code or color name for the scale text and border. Defaults to black. |
scaleTextSz |
Character. When type = |
A shiny UI for likert scale tasks.
if (interactive()){
library(shiny)
library(shinyjs)
ui <- fluidPage(
actionButton("btn", "Click me"),
rateUI(id = "example",
type = "button"),
actionButton("submit", "SUBMIT"),
textOutput("confirmation")
)
server <- function(input, output, session) {
rvs <- reactiveValues(rating = NULL)
observeEvent(input$btn, {
disable("btn")
rvs$ans <- rateServer(id = "example",
type = "button",
instructions = "What do you think?",
answers = c("Strongly disagree", "Disagree",
"Neutral", "Agree", "Strongly agree"),
pretext = "The vowels 'aw' and 'ah' sound exactly the same.")
})
observeEvent(input$submit, {
enable("btn")
output$confirmation <- renderText({
paste0("You selected ", rvs$ans$ratings[1],".")})
})
}
shinyApp(ui = ui, server = server)
}
# An example with 2 scales....
if (interactive()){
library(shiny)
library(shinyjs)
ui <- fluidPage(
actionButton("btn", "Click me"),
rateUI(id = "example",
type = "button",
n_scales = 2),
actionButton("submit", "SUBMIT"),
textOutput("confirmation")
)
server <- function(input, output, session) {
rvs <- reactiveValues(rating = NULL)
observeEvent(input$btn, {
disable("btn")
rvs$ans <- rateServer(id = "example",
trigger = NULL,
type = "button",
instructions = "Finish the sentence:",
answers = list(c("Sound completely the same",
"Sound similar, but not totally alike",
"Sound pretty different",
"Sound totally different"),
c("Are produced in the exact same way",
"Are produced similarly",
"Are produced pretty distinctly",
"Are produced in totally distinct ways")),
pretext = "The vowels 'aw' and 'ah'...",
n_scales = 2,
answer_all = TRUE,
direction = "vertical",
scale_labs = c("perception", "production"))
})
observeEvent(input$submit, {
enable("btn")
output$confirmation <- renderText({
paste0("You selected '", rvs$ans$ratings[1],"' and '", rvs$ans$ratings[2], "'.")})
})
}
shinyApp(ui = ui, server = server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.