Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Wasm R package binary assets downloading when exporting a Shinylive app #131

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This change switches from downloading the older webR VFS format to the newer (single .tgz file) format. Both repo.r-wasm.org and R-Universe are already publishing packages in this new format.

)
)
}
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)
georgestagg marked this conversation as resolved.
Show resolved Hide resolved
}, 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"
Loading