matchServer | R Documentation |
Matching Game Server Function
matchServer(
id = "game",
triggerInit,
triggerReturn,
startVal = 1,
result = c("hide", "disable"),
n2find,
n_items = 24,
n_cols = 4,
items = "default",
lab_type = c("icon", "text"),
randomTarget = TRUE,
randomGrid = FALSE,
size = 2,
color = "default",
fill = "default"
)
id |
The input ID associated with the matching game module. Must match the ID of |
triggerInit |
The reactive expression that triggers the initial appearance of the matching game. Must be created with or wrapped in |
triggerReturn |
The reactive expression that triggers the reappearance of the matching game UI. Must be created with or wrapped in |
startVal |
Integer or reactive expression that returns an integer. Default = 1. The participant's trial number when entering the game for this session. Useful if the participant resumes a game from a previous session. If using a reactive expression, should be wrapped in |
result |
A character value describing what should happen when the participant finds a match. Must be either "disable" or "hide". |
n2find |
Integer. How many items must the participant find in total? |
n_items |
Integer. How many items should be displayed? Should be evenly divisible by |
n_cols |
Integer. How many columns should the grid have? |
items |
Character. A list of items (either Font Awesome icons) or words to use as labels for the buttons. Default select a random sample of length |
lab_type |
Are the items text labels or icons? Must be either "text" or "icon" |
randomTarget |
Boolean. Should the targets be selected from the list randomly ( |
randomGrid |
Boolean. Should the grid of items be randomized for each participant? |
size |
An integer between 1 and 3 indicating the size of the matching game buttons (larger = bigger) |
color |
A single hex code or vector of hex codes indicating the color of the icons or text. Default is black. |
fill |
A single hex code or vector of hex codes indicating the fill of the matching game buttons. Defaults to values from the "Bright" colorblind friendly palette from Paul Tol (see link in references below). |
A reactive list with 4 items: (1) score = the number of matches the participant has found so far, (2) i_df = a data.frame containing the list of items used in the present game and their order, (3) time_df: a data frame containing the start and stop times for each trial and the difference between the two in milliseconds, and (4) a reactive value indicating whether the participant's answer is correct (1) or incorrect (0).
Paul Tol's colorblind-friendly palettes (the source of the default button colors) can be found at https://personal.sron.nl/~pault/#sec:qualitative.
Must be used with matchUI
.
library(shiny)
library(shinyjs)
# For the sake of a short example, we'll only require 3 matches.
ui <- fluidPage(
fluidRow(
column(width = 8, offset = 2,
actionButton("start", "Start"),
hidden(actionButton("again", "Play Again")),
matchUI()
)
)
)
server <- function(input, output, session) {
matches <- matchServer(triggerInit = reactive(input$start),
triggerReturn = reactive(input$again),
n2find = 3,
randomGrid = TRUE,
lab_type = "icon",
result = "hide")
observe({
if (matches()$n_found > 0) {
showElement("again")
}
})
}
shinyApp(ui = ui, server = server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.