I have an application hosted on the free tier of ShinyApps.io which calls callr::r_bg()
to initiate some long-running processes in the background. This works without a problem on my local machine, but the deployment on ShinyApps.io seems to be blocking the initialization of these new processes. Does anyone know if this is intended behavior?
Additional details:
I run background processes which are saved to a reactive value, and I later try to access the results of the background processes with get_result()
. I receive the following error message on ShinyApps.io.
Warning: Error in get_result(out, private$options): ! callr subprocess failed: could not start R, exited with non-zero status, has crashed or was killed
However, I have no issues running the app on my MacBook where I'm developing or on Linux (Ubuntu 22.02) where I simply downloaded the application and ran. The function for starting the background process is below
run_simulations_in_background <- function(sample_size, sample_prob, prob0, prob1, niter, included = "all",
.rng_kind = NULL, .rng_normal_kind = NULL, .rng_sample_kind = NULL,
tempfile = NULL) {
callr::r_bg(function(sample_size, sample_prob, prob0, prob1, niter, included,
.rng_kind, .rng_normal_kind, .rng_sample_kind, tempfile) {
run_simulation_wrapper <- function(sample_size, sample_prob, prob0, prob1, niter, included,
.rng_kind, .rng_normal_kind, .rng_sample_kind, tempfile) {
lapply(sample_size, function(x) {
try(writeLines(as.character(x), con = tempfile))
ordinalsimr::run_simulations(x, sample_prob = sample_prob, prob0 = prob0, prob1 = prob1, niter = niter, included = included,
.rng_kind = .rng_kind, .rng_normal_kind = .rng_normal_kind, .rng_sample_kind = .rng_sample_kind
)
}) |>
unlist(recursive = FALSE)
}
run_simulation_wrapper(sample_size, sample_prob, prob0, prob1, niter, included,
.rng_kind, .rng_normal_kind, .rng_sample_kind, tempfile)
},
args = list(sample_size, sample_prob, prob0, prob1, niter, included,
.rng_kind, .rng_normal_kind, .rng_sample_kind, tempfile),
package = "ordinalsimr"
)
}