README.md

Creating shiny widgets for quizes

Works for shiny events apps (see shinyEvents package). A quiz is currently described in yaml format and then parsed into R.

library(shinyQuiz)
# A simple multiple choice quiz
yaml = '
question: What is 20*20?
sc:
  - 100
  - 200
  - 400*
  - 500
success: Great, your answer is correct!
failure: Try again.
'

# A shiny app with events handling from shinyEvents
app = eventsApp()

qu = shinyQuiz(id="myquiz", yaml=yaml, quiz.handler=function(qu,solved,...) {
  cat("\nQuiz solved = ", solved)
})
app$ui = qu$ui
runEventsApp(app, launch.browser=rstudio::viewer)

The output looks as follows:

What is 20*20?

100
200
400
500
check

Showing a quiz solution as HTML

ui = quiz.ui(qu, solution=TRUE)
p(ui)

What is 20*20?

100
200
400
500
check

A quiz with mutliple parts

yaml = '
parts:
  - question: Which are square numbers?
    mc:
      - 12
      - 16*
      - 25*
      - 88
  - question: State pi up to 2 digits
    answer: 3.14
    roundto: 0.01
'

qu = shinyQuiz(id="myquiz", yaml=yaml, quiz.handler=function(qu,solved,...) {
  cat("\nQuiz solved = ", solved)
})

Cannot add quiz handlers since no shinyEvents app object is set.

# Show output as HTML
p(qu$ui)

Which are square numbers?

12
16
25
88

State pi up to 2 digits

check



skranz/shinyQuiz documentation built on May 30, 2019, 3:03 a.m.