Skip to content

Commit

Permalink
Record shiny and learnr events in the events table instead of shiny o…
Browse files Browse the repository at this point in the history
…r learnr tables
  • Loading branch information
phgrosjean committed Sep 15, 2024
1 parent cb4868d commit 90320c2
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: learnitdown
Type: Package
Version: 1.7.0
Version: 1.8.0
Title: R Markdown, Bookdown and Learnr Additions for Learning Material
Description: Extension to R Markdown, Bookdown and Learnr for building better
learning and e-learning material: H5P integration, course-contextual divs,
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# learnitdown 1.7.0

- `webshot_shiny()` now also accepts the path to a PNG file (the screenshot of the app) instead of the url to the Shiny application. This allows to create the webshot image in case the app cannot be accessed directly (for instance, a login in Posit Connect is required). The corresponding RStudio addin is modified to ask fpr a PNG screenshot if no suitable code is selected.
- Shiny and learnr events are now recorded in the "events" table instead of "shiny" or "learnr" tables.

# learnitdown 1.7.0

- `webshot_shiny()` now also accepts the path to a PNG file (the screenshot of the app) instead of the url to the Shiny application. This allows to create the webshot image in case the app cannot be accessed directly (for instance, a login in Posit Connect is required). The corresponding RStudio addin is modified to ask for a PNG screenshot if no suitable code is selected.

# learnitdown 1.6.0

Expand Down
8 changes: 4 additions & 4 deletions R/learnitdown_learnr.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ record_learnr <- function(tutorial_id, tutorial_version, user_id, event, data) {
}

# Try to access the database
m <- try(mongo(collection = "learnr", db = db, url = glue(url)),
m <- try(mongo(collection = "events", db = db, url = glue(url)),
silent = TRUE)
if (inherits(m, "try-error")) {
options(learnitdown_learnr_record = FALSE)
Expand Down Expand Up @@ -198,7 +198,7 @@ record_learnr <- function(tutorial_id, tutorial_version, user_id, event, data) {
use_db <- isTRUE(getOption("learnitdown_learnr_record", default = TRUE))
if (use_db) {
m <- try({
m <- mongo(collection = "learnr", db = db, url = glue(url))
m <- mongo(collection = "events", db = db, url = glue(url))
m$insert(toJSON(entry, auto_unbox = TRUE))
if (debug)
message("Learnr event '", entry$verb, "' inserted into database.")
Expand Down Expand Up @@ -237,7 +237,7 @@ record_learnr <- function(tutorial_id, tutorial_version, user_id, event, data) {
# url.server <- glue:glue(Sys.getenv("MONGO_URL_SERVER")
# if (isTRUE(server.db))
# url <- url.server
# mdb <- mongolite::mongo(collection = "learnr", db = db, url = url)
# mdb <- mongolite::mongo(collection = "events", db = db, url = url)
# if (mdb$count())
# mdb$find()
#}
Expand Down Expand Up @@ -354,7 +354,7 @@ Thanks.
subject = subject, address = address)
invisible(data)
} else {
message("No alearnr activity locally recorded")
message("No learnr activity locally recorded")
invisible(character(0))
}
}
Expand Down
6 changes: 3 additions & 3 deletions R/learnitdown_shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ read_shinylogs <- function(file, version = "0",
res
}

.record_shinylogs <- function(file, url, db, collection = "shiny",
.record_shinylogs <- function(file, url, db, collection = "events",
version = "0", log.errors = TRUE, log.outputs = FALSE,
debug = Sys.getenv("LEARNITDOWN_DEBUG", 0) != 0) {

Expand Down Expand Up @@ -290,7 +290,7 @@ debug = Sys.getenv("LEARNITDOWN_DEBUG", 0) != 0) {
#' @export
#'
#' @seealso [read_shinylogs()], [trackEvents()]
record_shiny <- function(path, url, db, collection = "shiny",
record_shiny <- function(path, url, db, collection = "events",
version = "0", log.errors = TRUE, log.outputs = FALSE, drop.dir = FALSE,
debug = Sys.getenv("LEARNITDOWN_DEBUG", 0) != 0) {
debug <- isTRUE(debug)
Expand Down Expand Up @@ -564,7 +564,7 @@ debug = Sys.getenv("LEARNITDOWN_DEBUG", 0) != 0) {
Sys.getenv('SHINY_PORT') == ""

is_server_up <- function(url, db) {
res <- try(mongo(collection = "shiny", db = db, url = url),
res <- try(mongo(collection = "events", db = db, url = url),
silent = TRUE)
!inherits(res, "try-error")
}
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ shinylogs
toc
UI
unserialize
webshot
Wordpress
xAPI
YAML
Expand Down
2 changes: 1 addition & 1 deletion man/record_shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/webshot_shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 90320c2

Please sign in to comment.