loading...

These functions provide the required code to be inserted in the server part of a Shiny application to track events (start, stop, inputs, outputs, errors, result or quit), to check the answer when the user clicks on the submit button and to cleanly close the application when the user clicks on the quit button.

trackEvents(
  session,
  input,
  output,
  sign_in.fun = NULL,
  url = Sys.getenv("MONGO_URL"),
  url.server = Sys.getenv("MONGO_URL_SERVER"),
  db = Sys.getenv("MONGO_BASE"),
  user = Sys.getenv("MONGO_USER"),
  password = Sys.getenv("MONGO_PASSWORD"),
  version = getOption("learnitdown.shiny.version"),
  path = Sys.getenv("LEARNITDOWN_LOCAL_STORAGE", "shiny_logs"),
  log.errors = TRUE,
  log.outputs = FALSE,
  drop.dir = TRUE,
  config = NULL,
  debug = Sys.getenv("LEARNITDOWN_DEBUG", 0) != 0
)

trackSubmit(
  session,
  input,
  output,
  solution = NULL,
  max_score = NULL,
  comment = "",
  message.success = "Correct",
  message.error = "Incorrect",
  score.txt = "Score",
  check.solution = check_shiny_solution
)

trackQuit(session, input, output, delay = 60)

check_shiny_solution(answer, solution)

Arguments

session

The current Shiny session.

input

The Shiny input object.

output

The Shiny output object.

sign_in.fun

The function that can get user info from the sign_in(), or NULL by default to disable using local user data.

url

The URL to reach the MongoDB database. By default, it is read from the MONGO_URL environment variable.

url.server

The URL to reach the MongoDB database. By default, it is read from the MONGO_URL_SERVER environment variable.

db

The database to populate in the MongoDB database. By default, it is read from the MONGO_BASE environment variable.

user

The user login to the MongoDB database. By default, it is read from the MONGO_USER environment variable.

password

The password to access the MongoDB database. By default, it is read from the MONGO_PASSWORD environment variable.

version

The version of the current Shiny application. By default, it is the learnitdown.shiny.version option, as set by learnitdownShinyVersion().

path

The path where the temporary shinylogs log files are stored. By default, it is set to the LEARNITDOWN_LOCAL_STORAGE environment variable, or to shiny_logs subdirectory of the application if not defined. If that directory is not writable, a temporary directory is used instead.

log.errors

Do we log error events (yes by default)?

log.outputs

Do we log output events (no by default)?

drop.dir

Do we erase the directory indicated by path = if it is empty at the end of the process (yes by default).

config

The result of the call to config(), if done.

debug

Do we debug recording of events using extra messages? By default, it is the value of the environment variable LEARNITDOWN_DEBUG, and debugging is activated when that value is different to 0.

solution

The correct solution as a named list. Names are the application inputs to check and their values are the correct values. The current state of these inputs will be compared against the solution, and the message.success or message.error is displayed accordingly. Also a result event is triggered with the correct field set to TRUE or FALSE accordingly. If solution = NULL, then the answer is considered to be always correct (use this if you just want to indicate that the user's answer is recorded in the database). For numeric values, use `c(min = x, max = y) to check if values are within a range.

max_score

The highest score value that could be attributed if the exercise is correctly done. By default, it is NULL meaning that the higher score would be equal to the number of items to check in solution.

comment

A string with a comment to append to the value of the result event.

message.success

The message to display is the answer is correct ("Correct" by default).

message.error

The message to display if the answer is wrong ("Incorrect" by default).

score.txt

The word to use for "score" ("Score" by default).

check.solution

The function to use to check if solution provided by a Shiny application is correct or not. By default, it is check_shiny_solution().

delay

The time to wait before we close the Shiny application in sec (60 sec by default). If delay = -1, the application is not closed, only the session is closed when the user clicks on the quit button.

answer

A named list of the answer data to check against solution. This object is provided by trackSubmit().

Value

The code to be inserted in the server part of the learnitdown Shiny application in order to properly identify the user and record the events.