Skip to content

Commit

Permalink
Try relative R package binaries before webR repo
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Mar 26, 2024
1 parent 64a3ab2 commit f839217
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/hooks/useWebR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ const load_r_pre = `
# Force internal tar - silence renv warning
Sys.setenv(TAR = "internal")
# Use mounted shiny R package library
.libPaths(c(.libPaths(), "/shiny"))
# Use shinylive R package libraries
dir.create("/shinylive/webr/packages", showWarnings = FALSE, recursive = TRUE)
.libPaths(c(.libPaths(), "/shinylive/webr/packages", "/shiny"))
# Shim R functions with webR versions (e.g. install.packages())
webr::shim_install()
Expand Down Expand Up @@ -250,6 +251,25 @@ webr::shim_install()
}
.webr_pkg_cache <- list()
lapply(rownames(installed.packages()), function(p) { .webr_pkg_cache[[p]] <<- TRUE })
.install_with_fallback <- function(package) {
# Don't try to re-mount installed package
if (isTRUE(.webr_pkg_cache[[package]])) return()
tryCatch({
webr::mount(
glue::glue("/shinylive/webr/packages/{package}"),
glue::glue("./packages/{package}/library.data")
)
has_pkg <- nzchar(system.file(package = package))
.webr_pkg_cache[[package]] <<- has_pkg
}, error = function(cond) {
# Fall back to the default webR package repository
webr::install(package)
})
}
.start_app <- function(appName, appDir) {
# Uniquely install packages with webr
Expand All @@ -261,7 +281,7 @@ webr::shim_install()
.webr_pkg_cache[[pkg_name]] <<- has_pkg
if (!has_pkg) {
webr::install(pkg_name)
.install_with_fallback(pkg_name)
}
})
Expand Down

0 comments on commit f839217

Please sign in to comment.