r-wasm / rwasm

Build R packages for WebAssembly and create a CRAN-like repo for distribution.
https://r-wasm.github.io/rwasm/
Other
57 stars 4 forks source link

Unable to render quarto doc with shinylive app using custom Wasm CRAN #43

Open DivadNojnarg opened 1 month ago

DivadNojnarg commented 1 month ago

I am not sure where to open this issue, as it involves quarto, webr, rwasm and shinylive. I am facing a new issue which I did not have few weeks ago.

I want to render a quarto document including some shinylive demos. These demos need to pull a package from a custom wasm CRAN I maintain.

The GA workflow fails if I use a specific tagged version of my custom package:

# That's what I ask in the workflow file to install the right blockr version
- uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: |
            posit-dev/r-shinylive
            any::knitr
            any::rmarkdown
            any::downlit
            any::xml2
            any::shinyMobile
            BristolMyersSquibb/blockr@v0.0.2.9023
            any::pracma
          cache-version: 2

The error I get:

Error in `get_github_wasm_assets()`:
! Can't find WebAssembly binary assets for
  github::BristolMyersSquibb/blockr@v0.0.2.9023
! Ensure WebAssembly binary assets are associated with the GitHub release
  "v0.0.2.9023".
ℹ WebAssembly binary assets can be built on release using GitHub Actions:
  <https://github.com/r-wasm/actions>
ℹ Alternatively, install a CRAN version of this package to use the default Wasm
  binary repository.

That's weird since the corresponding version should be available in my wasm CRAN. Besides, it just works fine in our pkgdown website which points to the same repo. The demo can also be found here.

I can also reproduce the error locally if I install the package with devtools::install_github("BristolMyersSquibb/blockr@v0.0.2.9023"). Fun fact: if I do devtools::install() from the blockr package project, I am able to compile the quarto document.

I followed what is written in the r-wasm instructions but now I am confused on how to move forward.

What did I do wrong?

DivadNojnarg commented 1 month ago

It seems to me that shinylive wants me to provide the .tgz for blockr with my GitHub release assets (as written in the message). However, that's absolutely not what I want as they are already here: https://bristolmyerssquibb.github.io/webr-repos/bin/emscripten/contrib/4.4/blockr_0.0.2.9023.tgz in my custom wasm CRAN.

georgestagg commented 1 month ago

When you install directly from the GitHub remote BristolMyersSquibb/blockr@v0.0.2.9023 using the extra-packages feature of r-lib/actions, the R Shinylive package is then unable to deduce the URL for your custom Wasm repository required to download the required binary for bundling with the application at build time. We can probably improve this, but for now that is the situation.

In theory, using something like the following in the GHA script should install the package directly from the custom Wasm repository, rather than from the source GitHub repo itself.

  run: Rscript -e 'install.packages("blockr", repos = "https://BristolMyersSquibb.github.io/webr-repos/")'

However, this does not seem to work because the source package https://BristolMyersSquibb.github.io/webr-repos/src/contrib/blockr_0.0.2.9023.tar.gz is missing -- That should not be the case, but I'm unsure right now what went wrong in the Wasm repo deployment to cause that.

In any case, you should be able to work around the issue for now by setting the SHINYLIVE_WASM_PACKAGES=0 environment variable before rendering your Quarto project. I think you can do that with:

      - name: Avoid bundling Shinylive packages
        run: echo "SHINYLIVE_WASM_PACKAGES=0" >> $GITHUB_ENV
georgestagg commented 1 month ago

It seems to me that shinylive wants me to provide the .tgz for blockr with my GitHub release assets (as written in the message). However, that's absolutely not what I want as they are already [...] in my custom wasm CRAN.

Yes, this is a newer feature for Shinylive to aid in reproducibility of deployed applications by bundling static package assets with the app. It can be turned off using the SHINYLIVE_WASM_PACKAGES method above.

Sorry about the poor documentation here, we're still figuring out how to make all this work together well.

DivadNojnarg commented 1 month ago

However, this does not seem to work because the source package https://BristolMyersSquibb.github.io/webr-repos/src/contrib/blockr_0.0.2.9023.tar.gz is missing -- That should not be the case, but I'm unsure right now what went wrong in the Wasm repo deployment to cause that.

Is it because of this:

Processing packages:
  ...
  /github/workspace/_site/src/contrib/blockr_0.0.2.9023_5f169ea.tar.gz
Run actions/upload-pages-artifact@v2
Run tar \
./
./src/
./src/contrib/
./src/contrib/blockr_0.0.2.9023_5f169ea.tar.gz