rateUI: User interface builder for likert scale tasks

View source: R/rateUI.R

rateUIR Documentation

User interface builder for likert scale tasks

Description

User interface builder for likert scale tasks

Usage

rateUI(
  id = "rate",
  type = c("button", "slider"),
  align = "center",
  n_scales = 1,
  scaleFillCol = "white",
  scaleTextCol = "black",
  scaleTextSz = "16px"
)

Arguments

id

The id of the module. Must be the same as the ID of rateServer().

type

One of 'button' or 'slider'. Which type of input will the respondents give? Must be the same as in the corresponding call to rateServer().

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 rateServer()

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 = button, a value indicating the size of the text on the scale. Defaults to "16px".

Value

A shiny UI for likert scale tasks.

Examples

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)
 }

abbey-thomas/speechcollectr documentation built on Nov. 19, 2024, 7:09 p.m.