Skip to contents

This example shows how to use the package ShinyItemBuilder with a custom end- and login-functions, to implement different approaches for authentication. We will use the items provided as demo01.

The Start of an Assessment

Anonymous Access

By default, ShinyItemBuilder is configured to give access to anyone that knows the URL.

library(ShinyItemBuilder)

item_pool <- getDemoPool("demo01")
assessment_config <- getConfig()
shinyApp(assessmentOutput(pool = item_pool, config = assessment_config,overwrite=T),
         renderAssessment)

Login Dialog

Using the option sessiontype="provided", this behavior can be changed.

library(ShinyItemBuilder)

item_pool <- getDemoPool("demo01")
assessment_config <- getConfig(sessiontype="provided")

assessment_config$login=function(session){
  showModal(modalDialog(
    tags$h2('Login'),
    tags$div('Please enter a valid token and press "OK".'),
    textInput('queryStringParameter', ''),
    footer=tagList(
      actionButton('submitLoginOK', 'OK')
    )
  ))
}

assessment_config$custom_list_accounts <- sprintf("%03d", 0:99)

assessment_config$validate=function(token_or_login=NULL, password=NULL, config){
  if (is.null(token_or_login)||length(token_or_login)==0)
  {
    return (FALSE)
  }
  else {
    if (!is.na(match(token_or_login,config$custom_list_accounts))){
      return (TRUE)
    }
  }
  FALSE
}
   
shinyApp(assessmentOutput(pool = item_pool, config = assessment_config,overwrite=T),
         renderAssessment)

The End of an Assessment

Multiple Runs

To allow multiple runs, the end-function needs to contain an actionButton with the name endActionButtonOK:

assessment_config$end=function(session){
    showModal(modalDialog(
      title = "You Answered all Items",
      "Please close the browser / tab or click 'Restart'.",
      footer = tagList(actionButton("endActionButtonOK", "Restart"))))
  }

Single Runs (End-Page)

If the end-function does not contain an actionButton with the name endActionButtonOK, the test-taker can not restart the assessment, as long as the session is stored in the browser.

assessment_config$end=function(session){
    showModal(modalDialog(
      title = "You Answered all Items",
      "Please close the browser / tab.",
      footer = tagList()))
  }

Single Runs (Redirect)

assessment_config$end=function(session){
  session$sendCustomMessage("shinyassess_redirect", 
      "https://URL-TO-REDIRECT.SOMEWERE/?QUERYSTRING")
}