mirror of
https://github.com/johrpan/geposanui.git
synced 2025-10-26 11:17:24 +01:00
Move caching to geposan
This commit is contained in:
parent
33c8292690
commit
4cf5bff125
2 changed files with 3 additions and 34 deletions
11
R/server.R
11
R/server.R
|
|
@ -30,14 +30,9 @@ server <- function(input, output, session) {
|
||||||
results <- withProgress(
|
results <- withProgress(
|
||||||
message = "Analyzing genes",
|
message = "Analyzing genes",
|
||||||
value = 0.0, {
|
value = 0.0, {
|
||||||
run_cached(
|
geposan::analyze(preset, function(progress) {
|
||||||
rlang::hash(preset),
|
setProgress(progress)
|
||||||
geposan::analyze,
|
})
|
||||||
preset,
|
|
||||||
function(progress) {
|
|
||||||
setProgress(progress)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
26
R/utils.R
26
R/utils.R
|
|
@ -1,29 +1,3 @@
|
||||||
# Run a function caching the result on the file system.
|
|
||||||
#
|
|
||||||
# The function will be called with the appended arguments. The [`id`] argument
|
|
||||||
# will be used to identify the cache file on the file system and in log
|
|
||||||
# messages.
|
|
||||||
run_cached <- function(id, func, ...) {
|
|
||||||
if (!dir.exists("cache")) {
|
|
||||||
dir.create("cache")
|
|
||||||
}
|
|
||||||
|
|
||||||
cache_file <- paste("cache/", id, ".rds", sep = "")
|
|
||||||
|
|
||||||
if (file.exists(cache_file)) {
|
|
||||||
# If the cache file exists, we restore the data from it.
|
|
||||||
readRDS(cache_file)
|
|
||||||
} else {
|
|
||||||
# If the cache file doesn't exist, we have to do the computation.
|
|
||||||
data <- func(...)
|
|
||||||
|
|
||||||
# The results are cached for the next run.
|
|
||||||
saveRDS(data, cache_file)
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# This is needed to make data.table's and shiny's symbols available within the
|
# This is needed to make data.table's and shiny's symbols available within the
|
||||||
# package.
|
# package.
|
||||||
#' @import data.table
|
#' @import data.table
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue