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

Export R shinylive apps with Wasm package binaries included in static assets #72

Merged
merged 11 commits into from
Apr 18, 2024

Conversation

georgestagg
Copy link
Collaborator

@georgestagg georgestagg commented Apr 9, 2024

Fixes #65


A first-pass implementation of #63.

Exports shinylive apps with Wasm R binary packages downloaded and included in .../shinylive/webr/packages. Metadata is stored in .../shinylive/webr/packages/metadata.rds and loaded at runtime.

For shinylive::export(), you can disable Wasm package bundling with wasm_packages = FALSE. And disable using the cache with package_cache = FALSE. Both are TRUE by default, meaning Wasm packages will be downloaded and bundled.

For Quarto documents with embedded R Shinylive apps, quarto_ext.R is updated so that app.json bundles passed to the shinylive R package are decoded onto disk, and then R Wasm binaries are downloaded using the same tools as created for shinylive::export(). Finally the resulting list of binaries are passed back to Quarto as HTML dependencies.

Metadata is merged over subsequent runs since (in e.g. Quarto docs) we can have multiple app.json bundles, and we want all referenced packages to be available in the static assets.


Recursive dependencies are resolved using the pkgdepends package. This can get slow for large local package libraries (My R library has all of CRAN installed, for unrelated reasons, and so it takes a few seconds to resolve). We might want to think about how we could make use of r-lib/pkgcache in future. This should be "fine" for the moment, though.


Note: Requires the shinylive assets bundle from posit-dev/shinylive#121

@georgestagg georgestagg requested a review from schloerke April 9, 2024 15:14
@georgestagg georgestagg force-pushed the relative-package-binaries branch from f0e197c to 77decbc Compare April 9, 2024 16:08
@georgestagg georgestagg force-pushed the relative-package-binaries branch 2 times, most recently from 7e4de44 to 29f29fe Compare April 10, 2024 07:24
@georgestagg
Copy link
Collaborator Author

georgestagg commented Apr 10, 2024

Note: I think the "integration" test fails because /local/quarto also includes a python Shinylive app, and the Shinylive assets from posit-dev/shinylive@main are not yet compatible with the posit-dev/py-shinylive repo.

From what I can tell, it looks like the file repodata.json was renamed to pyodide-lock.json in a Pyodide update, but repodata.json is still referenced by the python CLI interface. Once that's been updated in posit-dev/py-shinylive, hopefully the test should pass.

Even with some missing dependencies, an app may work correctly. For
example, the `curl` package could be a dependency of a used Wasm
package, but if network functionality is avoided never actually used at
runtime.

So for missing packages installed locally from a CRAN-like repo, we
issue a warning and only include the package without any Wasm assets.

For GitHub packages we are still strict and require that the package
exists.
@wch
Copy link
Contributor

wch commented Apr 16, 2024

@georgestagg Thanks for pointing out the issue with repodata.json being renamed to pyodide-lock.json. This is a good reminder of why we can’t just have the r-shinylive or py-shinylive packages deploy arbitrary versions of the shinylive assets.

R/export.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
R/packages.R Outdated Show resolved Hide resolved
@georgestagg georgestagg merged commit f24ed97 into main Apr 18, 2024
12 checks passed
@georgestagg georgestagg deleted the relative-package-binaries branch April 18, 2024 14:02
@schloerke schloerke mentioned this pull request Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't read RDS files
3 participants