From 720a1f16a003416b730b4f874094d31b4f185dde Mon Sep 17 00:00:00 2001 From: Martin Jung Date: Mon, 29 Apr 2024 14:15:02 +0200 Subject: [PATCH] Adding shinylogs recording to app --- .gitignore | 3 +++ DESCRIPTION | 1 + R/app_server.R | 6 ++++++ dev/rm_logs.R | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 dev/rm_logs.R diff --git a/.gitignore b/.gitignore index a58fe7e..6077f75 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ tests/testthat/*.pdf # Shiny bookmarks shiny_bookmarks/ + +# Ignore log files +logs/ diff --git a/DESCRIPTION b/DESCRIPTION index ba0b06c..9987744 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,6 +16,7 @@ Imports: shinyWidgets, shinyjs, shinyFeedback, + shinylogs, sever, fresh, DT, diff --git a/R/app_server.R b/R/app_server.R index 8b59ffd..a0fd09d 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -14,6 +14,12 @@ app_server <- function(input, output, session) { session$doBookmark() }) + # Enable shinylogs + # shinylogs::read_rds_logs("logs") + shinylogs::track_usage(what = c("session", "input", "output", "error"), + storage_mode = shinylogs::store_rds(path = "logs/") + ) + # fake reload at start shiny::observeEvent(input$reload, { session$reload() diff --git a/dev/rm_logs.R b/dev/rm_logs.R new file mode 100644 index 0000000..0f4e865 --- /dev/null +++ b/dev/rm_logs.R @@ -0,0 +1,20 @@ +# This maintenance script simply deletes all files in the log folder of the app +# To run simply do Rscript inst/rm_logs.R +# --- # + +library(assertthat) + +# Get all log files +ll <- list.files("logs/", full.names = TRUE) +ll <- ll[assertthat::has_extension(ll, "rds")] + +# No logs found +if(length(ll)==0){ + message("No logs found...") +} else { + # Message + message("Found a total of ", length(ll), " log files. Deleting them all?") + if(utils::askYesNo(msg = "Delete?")){ + sapply(ll, file.remove) + } +}