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)
The current Shiny session
.
The Shiny input
object.
The Shiny output
object.
The function that can get user info from the
sign_in()
, or NULL
by default to disable using local user data.
The URL to reach the MongoDB database. By default, it is read from
the MONGO_URL
environment variable.
The URL to reach the MongoDB database. By default, it is
read from the MONGO_URL_SERVER
environment variable.
The database to populate in the MongoDB database. By default, it is
read from the MONGO_BASE
environment variable.
The user login to the MongoDB database. By default, it is
read from the MONGO_USER
environment variable.
The password to access the MongoDB database. By default, it
is read from the MONGO_PASSWORD
environment variable.
The version of the current Shiny application. By default, it
is the learnitdown.shiny.version
option, as set by
learnitdownShinyVersion()
.
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.
Do we log error events (yes by default)?
Do we log output events (no by default)?
Do we erase the directory indicated by path =
if it is
empty at the end of the process (yes by default).
The result of the call to config()
, if done.
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
.
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.
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
.
A string with a comment to append to the value of the result event.
The message to display is the answer is correct ("Correct" by default).
The message to display if the answer is wrong ("Incorrect" by default).
The word to use for "score" ("Score" by default).
The function to use to check if solution provided by
a Shiny application is correct or not. By default, it is
check_shiny_solution()
.
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.
A named list of the answer data to check against solution. This
object is provided by trackSubmit()
.
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.