matchUI: Matching Game User Interface

View source: R/matchUI.R

matchUIR Documentation

Matching Game User Interface

Description

Matching Game User Interface

Usage

matchUI(
  id = "game",
  title = "Find a Match!",
  instructions =
    "Click a button in the grid below to see the image it is hiding.\n                                  Keep clicking buttons until you find\n                                  the image that matches the one above."
)

Arguments

id

The input ID associated with the matching game module. Must match the ID of matchServer().

title

Character. The title that will be displayed at the top of the UI. Defaults to "Find a Match!"

instructions

Character. The instructions that will be displayed above the grid of buttons. Defaults to general instructions for the matching game.

Value

A minimal user interface for the matching game that includes a title, instructions, and a progress bar.

See Also

Must be used with matchServer.

Examples

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)


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