posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
147 stars 15 forks source link

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

Closed georgestagg closed 3 months ago

georgestagg commented 3 months ago

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 https://github.com/posit-dev/shinylive/pull/121

georgestagg commented 3 months ago

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.

wch commented 3 months ago

@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.