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

Versions not matching between WebR repository and Quarto page #22

Closed
jbryer opened this issue May 27, 2024 · 9 comments
Closed

Versions not matching between WebR repository and Quarto page #22

jbryer opened this issue May 27, 2024 · 9 comments

Comments

@jbryer
Copy link

jbryer commented May 27, 2024

Sorry if this is not the correct place to post this. I am trying to setup a Github repository for an R package that will be used in a Quarto book. I have implemented Shiny applications within the R package (see https://github.com/jbryer/WebRBookTemplate/blob/master/R/loess_shiny.R for example). I am trying to embed this within my Quarto book site using shinylive (see this page: https://github.com/jbryer/WebRBookTemplate/blob/master/book/index.qmd).

I have a couple of Github actions here to create a WebR repository and create the Quarto book adapted from another action for pkgdown. It seems I am almost there except the Wasm build is building for version 4.4 (https://github.com/jbryer/WebRBookTemplate/tree/gh-pages/bin/emscripten/contrib/4.4) and the Quarto website is looking for version 4.3 (according to the JavaScript console preload error:Warning: unable to access index for repository https://jbryer.github.io/WebRBookTemplate/bin/emscripten/contrib/4.3:). Is there a way to either 1. Have Wasm build multiple versions or 2. Make the two actions use the same version?

Thanks so much for any help you can provide.

@jbryer
Copy link
Author

jbryer commented May 27, 2024

I think this issue over on the shinylive Github repo is related: posit-dev/shinylive#131

@georgestagg
Copy link
Member

I've merged #20, which allows you to select the webR image version when building your R package for Wasm.

In .github/workflows/deploy-cran-repo.yaml, update your build-rwasm job to point to the webR v0.3.3 image:

      - name: Build WASM R packages
        uses: r-wasm/actions/build-rwasm@v1
        with:
          packages: "."
          repo-path: "_site"
          webr-image: "ghcr.io/r-wasm/webr:v0.3.3"

That particular fixed version of webR is running R v4.3.3, and so the R packages compiled for wasm will be built into the repo directory /bin/emscripten/contrib/4.3.

Hopefully, this should fix the issue. Please let me know if not!

@jbryer
Copy link
Author

jbryer commented May 28, 2024

Thanks for looking into this so quickly. I updated my GitHub actions but am getting this error:

Run docker build build-rwasm --build-arg WEBR_IMAGE=ghcr.io/r-wasm/webr:v0.3.3 -t r-wasm-build-rwasm:${GITHUB_SHA}
  docker build build-rwasm --build-arg WEBR_IMAGE=ghcr.io/r-wasm/webr:v0.3.3 -t r-wasm-build-rwasm:${GITHUB_SHA}
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    GITHUB_PAT: ***
    R_LIBS_USER: /home/runner/work/_temp/Library
    TZ: UTC
    _R_CHECK_SYSTEM_CLOCK_: FALSE
    NOT_CRAN: true
    RSPM: https://packagemanager.posit.co/cran/__linux__/jammy/latest
    RENV_CONFIG_REPOS_OVERRIDE: https://packagemanager.posit.co/cran/__linux__/jammy/latest
ERROR: unable to prepare context: path "build-rwasm" not found
Error: Process completed with exit code 1.

The run log is here: https://github.com/jbryer/WebRBookTemplate/actions/runs/9270561119/job/25503863687

@georgestagg
Copy link
Member

Thank you for the run log, that's very useful!

I've made a further tweak to the script, could you please try once more using the same GitHub Actions script for me?

@jbryer
Copy link
Author

jbryer commented May 28, 2024

Thank you so much George. That resolved the issue with building and loading the package. I see a different problem now, not sure if you have any idea. I am trying to embed a shiny app where the UI and server functions are defined in the package. When I load this page: https://jbryer.github.io/WebRBookTemplate/ I get this error (you can see the full context by viewing the JavaScript console):

Refused to execute a script because its hash, its nonce, or 'unsafe-inline' appears in neither the script-src directive nor the default-src directive of the Content Security Policy.

If I preview the Quarto site locally it loads just fine. Am I doing something that is not allowed?

@jbryer
Copy link
Author

jbryer commented May 28, 2024

To provide some additional context, if I deploy the app standalone to the same Github pages repo, it works:
https://jbryer.github.io/WebRBookTemplate/shiny/loess/
Seems to be something when it is embedded within Quarto. Here is the app.R source:

if(require(webr)) {
	webr::install("WebRBookTemplate", repos = c("https://jbryer.github.io/WebRBookTemplate/", "https://repo.r-wasm.org/"))
}
library(WebRBookTemplate)
library(shiny)
shiny::shinyApp(ui = WebRBookTemplate::loess_shiny_ui,
				server = WebRBookTemplate::loess_shiny_server)

@jbryer
Copy link
Author

jbryer commented May 29, 2024

Sorry to spam this thread but wanted to provide an update. It works fine in Google Chrome but not Safari.

@georgestagg
Copy link
Member

georgestagg commented May 30, 2024

Sorry to spam this thread but wanted to provide an update.

No worries, that's what the threads are for.

It works fine in Google Chrome but not Safari.

At the risk of using "it works on my machine", your app does seem to be running OK in Safari for me and I don't see that particular error in my JS console.

Screenshot 2024-05-30 at 09 14 55

Perhaps you are seeing a cached version of your published Quarto document? Can you try clearing your Safari browser cache and loading the published page again?

@jbryer
Copy link
Author

jbryer commented May 30, 2024

Thanks for your help. I tried it in a private window and the shiny app loads. I'll close this. Great work BTW, really appreciate it.

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

No branches or pull requests

2 participants