headphoneTestServer: Server Function for the Headphone Test Module

View source: R/headphoneTestServer.R

headphoneTestServerR Documentation

Server Function for the Headphone Test Module

Description

The server portion of the Headphone Test module. Make your headphoneTestUI() do things!

Usage

headphoneTestServer(
  id = "headphone_test",
  trigger = NULL,
  type = c("huggins", "antiphase"),
  n_trials = 6,
  threshold,
  n_attempts = 2,
  warn_msg = "default",
  fail_msg = "default",
  success_msg = "default"
)

Arguments

id

The Id of this module. Must match the Id of headphoneTestUI(). Defaults to "headphone_test".

trigger

Optional. A reactive expression indicating the event that should trigger the appearance of the consent form. Must be wrapped in reactive().

type

Whether to use the Huggins Pitch headphone screen (see Milne et al., 2020) or the Antiphase headphone screen (Woods et al., 2017). Must be one of "huggins" or "antiphase" and must match the value given in headphoneTestUI().

n_trials

Integer. How many trials should be presented to each participant? Defaults to 6. Must match the n_trials argument of headphoneTestUI()

threshold

Integer. How many trials must a participant get correct to pass the screen?

n_attempts

Integer. How many attempts to pass the screen should a participant get? Defaults to 2.

warn_msg

An optional character vector. Customize the text of the warning message that appears when a participant fails the screen but is given another opportunity to pass.

fail_msg

An optional character vector. Customize the text of the message shown to participants when they fail the headphone screen on their final attempt.

success_msg

An optional character vector. Customize the text of the "success" message when the participant passes the headphone screen.

Value

A reactive value, status, that has a value of 0 (failed/did not complete headphone screen) or 1 (passed headphone screen).

References

Milne, A.E., Bianco, R., Poole, K.C., Zhao, S., Oxenham, A.J., Billing, A.J., & Chait, M. 2021. An online headphone screening test based on dichotic pitch.Behavior Research Methods 53, 1551-1562.
Woods, K.J.P., Siegel, M.H., Traer, J., & McDermott, J.H. 2017. Headphone screening to facilitate web-based auditory experiments. Attention, Perception, & Psychophysics 79, 2064-2072.

See Also

wwwPrep, headphoneTestUI

Other headphone screen module: headphoneTestUI()

Examples

## First use wwwPrep() to get the data for the type of headphone screen you want.
## NOTE: Do NOT put this command in your UI!
# Run it once before testing your app to create the www folder.
wwwPrep(HugginsPitchScreen = TRUE)

# Now build the app.
if (interactive()) {
 ui <- fluidPage(
        headphoneTestUI(id = "headphone_test", type = "huggins"),
        textOutput("done")
     )

 server <- function(input, output, session) {
   # Give the reactive value output a name, so it can be checked and accessed later.
           phones <- headphoneTestServer(id = "headphone_test", type = "huggins",
                                         n_trials = 6, threshold = 4, n_attempts = 2)
           observeEvent(phones(), {
             if (phones() == 1) {
                 output$done <- renderText("Headphone test successfully completed!")
                 }
              })
  }
shinyApp(ui = ui, server = server)
}

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