non_coding: Shiny module to create a non-coding exercise

Description Usage Arguments Examples

View source: R/noncoding.R

Description

Shiny module to create a non-coding exercise

Usage

1
2
3
non_coding(input, output, session, feedback)

non_coding_ui(id)

Arguments

input

standard shiny boilerplate

output

standard shiny boilerplate

session

standard shiny boilerplate

feedback

a reactive that returns a named list with a message and feedback

id

id to call the module with

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 
 library(shiny)
 num <- sample(1:10, 1)

 check_exercise <- function(actual, guess){
   if(actual == guess){
     list(message = "Well Done!", success = TRUE)
   } else {
     msg <- sprintf("You guessed %s. Please try again!", guess)
     list(message = msg, success = FALSE)
   }
 }

 ui <- fluidPage(
   theme = shinythemes::shinytheme('cosmo'),
   titlePanel('Guess the Number'),
   mainPanel(
     sliderInput('num', 'Select number', 0, 10, 2),
     non_coding_ui('feedback')
   )
 )

 server <- function(input, output, session){
   feedback <- reactive({
     check_exercise(num, input$num)
   })
   shiny::callModule(non_coding, 'feedback', feedback)
 }
 shinyApp(ui = ui, server = server)

## End(Not run)

datacamp/rexplorables documentation built on June 6, 2021, 4:12 p.m.