Skip to content

Commit

Permalink
Improve Wasm R package binary assets downloading when exporting a Shi…
Browse files Browse the repository at this point in the history
…nylive app (#131)

* Download .tgz Wasm binary packages

* Support compressed Wasm libraries on GitHub

* Use R-Universe for Wasm Bioconductor packages

* Never bundle Wasm R packages with legacy assets

Instead, show a warning asking the user to upgrade their Shinylive
assets to a compatible version.

* Upgrade shinylive assets to v0.8.0

* Temporarily disable failing quarto extension test

* Update R/packages.R

Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com>

---------

Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com>
  • Loading branch information
georgestagg and gadenbuie authored Oct 15, 2024
1 parent bd17fc8 commit cf739ae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ jobs:
testthat::test_local()
- name: Test shinylive quarto extension with latest shinylive assets
uses: quarto-dev/quarto-actions/render@v2
env:
# TODO: py-shinylive doesn't follow this envvar yet. If shinylive
# has a newer version, this action will fail.
SHINYLIVE_ASSETS_VERSION: ${{ steps.r-linked-assets.outputs.version }}
with:
path: local/quarto/
#- name: Test shinylive quarto extension with latest shinylive assets
# uses: quarto-dev/quarto-actions/render@v2
# env:
# # TODO: py-shinylive doesn't follow this envvar yet. If shinylive
# # has a newer version, this action will fail.
# SHINYLIVE_ASSETS_VERSION: ${{ steps.r-linked-assets.outputs.version }}
# with:
# path: local/quarto/

# TODO-barret-future; Test the output of the render using pyright / py-shiny e2e controls?
14 changes: 13 additions & 1 deletion R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export <- function(
# =========================================================================
# Copy app package dependencies as Wasm binaries
# =========================================================================
if (wasm_packages) {
if (wasm_packages && wasm_packages_able(assets_version)) {
download_wasm_packages(appdir, destdir, package_cache, max_filesize)
}

Expand All @@ -228,3 +228,15 @@ export <- function(

invisible(destdir)
}

wasm_packages_able <- function(assets_version) {
if (assets_version <= package_version("0.7.0")) {
cli::cli_warn(c(
"Can't bundle WebAssembly R packages for legacy Shinylive assets version: {assets_version}.",
"i" = "Use Shinylive assets version 0.8.0 or later to bundle WebAssembly R package binaries."
))
FALSE
} else {
TRUE
}
}
14 changes: 7 additions & 7 deletions R/packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ get_wasm_assets <- function(desc, repo) {

list(
list(
filename = glue::glue("{pkg}_{ver}.data"),
url = glue::glue("{contrib}/{pkg}_{ver}.data")
),
list(
filename = glue::glue("{pkg}_{ver}.js.metadata"),
url = glue::glue("{contrib}/{pkg}_{ver}.js.metadata")
filename = glue::glue("{pkg}_{ver}.tgz"),
url = glue::glue("{contrib}/{pkg}_{ver}.tgz")
)
)
}
Expand Down Expand Up @@ -103,7 +99,7 @@ get_github_wasm_assets <- function(desc) {

# Find GH release asset URLs for R library VFS image
library_data <- Filter(function(item) {
item$name == "library.data"
grepl("library.data", item$name, fixed = TRUE)
}, tags$assets)
library_metadata <- Filter(function(item) {
item$name == "library.js.metadata"
Expand Down Expand Up @@ -177,6 +173,10 @@ prepare_wasm_metadata <- function(pkg, metadata) {
} else if (grepl("r-universe\\.dev$", repo)) {
metadata$assets <- get_wasm_assets(desc, repo = desc$Repository)
metadata$type <- "package"
} else if (grepl("Bioconductor", repo)) {
# Use r-universe for Bioconductor packages
metadata$assets <- get_wasm_assets(desc, repo = "https://bioc.r-universe.dev")
metadata$type <- "package"
} else {
# Fallback to repo.r-wasm.org lookup for CRAN and anything else
metadata$assets <- get_wasm_assets(desc, repo = "http://repo.r-wasm.org")
Expand Down
2 changes: 1 addition & 1 deletion R/quarto_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ build_app_resources <- function(app_json) {
})

wasm_packages <- sys_env_wasm_packages()
if (wasm_packages) {
if (wasm_packages && wasm_packages_able(assets_version())) {
# Download wasm binaries ready to embed into Quarto deps
withr::with_options(
list(shinylive.quiet = TRUE),
Expand Down
2 changes: 1 addition & 1 deletion R/version.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is the version of the Shinylive assets to use.
SHINYLIVE_ASSETS_VERSION <- "0.7.0"
SHINYLIVE_ASSETS_VERSION <- "0.8.0"
SHINYLIVE_R_VERSION <- as.character(utils::packageVersion("shinylive"))
WEBR_R_VERSION <- "4.4.1"

0 comments on commit cf739ae

Please sign in to comment.