r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
804 stars 54 forks source link

problems installing/mounting package #408

Open richardjtelford opened 2 months ago

richardjtelford commented 2 months ago

I have made a package containing shiny apps that I want to add to a quarto document using shinylive-r and webr. I think I have managed to get the package to compile to a library.data file with github actions.

The problem I'm having is having is to install the package in webr.

I tried using webr::mount() but my browser tab crashed with this code

webr::mount("/my-library", "https://github.com/biostats-r/shinystats/releases/download/v0.2/library.data")
.libPaths(c(.libPaths(), "/my-library"))

Then I tried webr::install()

webr::install("shinystats", repo = "https://github.com/biostats-r/shinystats/releases/download/v0.2/library.data")

This gave me the message "Not Found" after a couple of minutes.

I wonder if I have not managed to deploy correctly on github, but the file url works.

I'm also not understanding the advantages/disadvantages of mount() vs install()

georgestagg commented 2 months ago

We will soon release an update for shinylive-r that will handle this situation automatically by downloading the Wasm binaries attached to your R package's v0.2 release from GitHub and distributing it alongside your Shiny app.

In the meantime, you will need to use a slightly different Github Action to build a CRAN-like repo rather than building and releasing a Wasm filesystem image. With this method, you will use install() rather than mount().

There are instructions in the rwasm documentation at Setting up the GitHub repository that walk you through setting up a new GitHub repository to contain your CRAN-like repo, where you can add your custom R package as part of a list of packages provided by the repo.

Alternatively, there are some community-provided tutorials at https://github.com/coatless-tutorials/webr-unified-gh-workflow working though a similar process to build and serve a CRAN-like repository for you package.


The process of using filesystem images and using mount() has the advantage that it is more efficient, but the disadvantage that it requires more control over your static server and deployment process than currently provided by shinylive-r and GitHub Pages. As I mentioned above, we're currently working on improving the situation so that this is no longer a problem, but for the moment using the install() method is simpler to implement for your app.