From cf739aef107a9040c34b62309dea5bdbe8439945 Mon Sep 17 00:00:00 2001 From: George Stagg Date: Tue, 15 Oct 2024 13:54:47 +0100 Subject: [PATCH] Improve Wasm R package binary assets downloading when exporting a Shinylive 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 --------- Co-authored-by: Garrick Aden-Buie --- .github/workflows/R-CMD-check.yaml | 16 ++++++++-------- R/export.R | 14 +++++++++++++- R/packages.R | 14 +++++++------- R/quarto_ext.R | 2 +- R/version.R | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 025cb33..98c7daf 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -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? diff --git a/R/export.R b/R/export.R index 8e02948..946f36a 100644 --- a/R/export.R +++ b/R/export.R @@ -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) } @@ -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 + } +} diff --git a/R/packages.R b/R/packages.R index b6f8a46..2a47413 100644 --- a/R/packages.R +++ b/R/packages.R @@ -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") ) ) } @@ -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" @@ -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") diff --git a/R/quarto_ext.R b/R/quarto_ext.R index acc53a6..4eaab56 100644 --- a/R/quarto_ext.R +++ b/R/quarto_ext.R @@ -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), diff --git a/R/version.R b/R/version.R index e42b181..a9c0cd1 100644 --- a/R/version.R +++ b/R/version.R @@ -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"