r-wasm / actions

GitHub Actions associated with R WebAssembly tasks
MIT License
25 stars 6 forks source link

Fail to get package with repo hosted on GitHub Page #18

Open DivadNojnarg opened 7 months ago

DivadNojnarg commented 7 months ago

Below is what I did for a recent project:

  1. I setup a wasm CRAN here: https://github.com/RinteRface/rinterface-wasm-cran following the doc from here.
  2. I try to install {shinyMobile} from the provided url: https://rinterface.github.io/rinterface-wasm-cran/. Demo shinylive app is here
webr::install("shinyMobile", repos = "https://rinterface.github.io/rinterface-wasm-cran/")
Warning: unable to access index for repository https://rinterface.github.io/rinterface-wasm-cran/bin/emscripten/contrib/4.3:
  download from 'https://rinterface.github.io/rinterface-wasm-cran/bin/emscripten/contrib/4.3/PACKAGES' failed
  1. Then, if I manually upload the same GA artifact to Netlify + custom headers (this would not work without):
    
    #netlify.toml

[[headers]] for = "/" [headers.values] Access-Control-Allow-Origin = "" Access-Control-Allow-Headers = "" Access-Control-Allow-Methods = ""


I can download the packages and run the [app](https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRASwgGdSoAbbgCgA6YAOapuRUuyEBKARFqNmbTj35D2ACzYBPALJE6LbnCG4ABAzioi7MwF4zQjaVKp2iAPQeAbN4CMAJwBdAAc9AT0IQEAzCEArAAmfgAs0X4hAOwAtFkAZgxQdABWRACu7Fmk1EYsws5ZdNHeCd4hGBBwpNwsudoYaKgeMnJy3YxQDNp8mjqyEGMFk9NaEHoGRnBzcjOrAILoghBmZqUs9ma5GQAKUMJwh8fHpCxdcOdCAKqoCVDkFxkAZRgE1IALgxgIpFMcke-wBbGExgAMlBtGVSA9YWZoAA3OgTc6XAByUDxEz4z1e7zAXx+f0uQJBYIhULA0lwMKxlwAQuICABrPg80ouEiCMClb6-Ex4Rw0qV-RkMUhmZlwSEydmc2GXJEsTiYrFmZSdc4AFSwHwAohyjkazJwGCRhObLTbtVj0d0Oq7rbb7XDgcq1ZDDfa2KgRQBJBLU9hByTg9Ws-0BszcQrg6kAYQ0RBsbygZhxExYhWMiGhdoDBDzLAitgc7DELz4xG40Hg7D4MFIBAm7GAWT8AF12RYrHw-Ig4tItdX7URUBQo0cHEJrJHUEIPbC5kb50auHRjAB5EWRjFCOlQYYL-dmQ8OuAMHEvwmlCCQlhiiMi8zope5jsHA7DsD+EDSGYIAeoBIoACQ3mYAA8WQThACQvma5b3LuZi9v2DCDuYBDijAqDCKYxoQJe8HxiCIEsuOCROqg5wAGK7EiAJWiOqawk61CdqBvpWh6WwLgYIGvnAVpvmQfB-qQ8GSnScDmDBC7HKp0rsYCCYhleWmPEpMZxgmjHJlWAZLiua5ypocCdNZ9qWZCcCxuuYAaNueB4cctZEPWIkOKRTi+eYQh3BMVFCIRdAyPxWIwKU3DPGIbwOBafr+fhUAAB5IhQwikBo5wAEx4Q+xwAL4PjVcjSGANUjkAA) with the correct package version

webr::install("gplots") webr::install("shinyMobile", repos = "https://66199b8ebceb89385d143187--frabjous-twilight-b36d68.netlify.app/")

Working well



This used to work in the past months. Roughly 4 months ago I setup the same infrastructure on a non CRAN package and could download it from the wasm CRAN: https://github.com/blockr-org/webr-repos/commit/d05444f00021b281014b31235e75d8c1e025945e). This other setup is now also broken.

My understanding is that upload page artifact is in beta and evolving so things might have changed.
georgestagg commented 7 months ago

As discussed in https://github.com/r-wasm/actions/issues/15#issuecomment-1924234922, we changed the default so that package dependencies are not included in a CRAN-like repo by default. It's possible the rwasm package documentation is out of date, but we plan to rework it all at some point in any case.

I am able to make your repository work by including the default webR binary repository as a fallback for all the dependent packages.

webr::install(
  "shinyMobile",
  repos = c("https://rinterface.github.io/rinterface-wasm-cran/", "https://repo.r-wasm.org")
)
> library(shinyMobile)
> shinyMobile::getF7Colors()
 [1] "primary"    "red"        "green"      "blue"       "pink"       "yellow"    
 [7] "orange"     "purple"     "deeppurple" "lightblue"  "teal"       "lime"      
[13] "deeporange" "gray"       "black" 
DivadNojnarg commented 7 months ago

The goal here was to put and try a development version of shinyMobile, that is 2.0.0. The official wasm CRAN points to 1.0.1 that is the latest CRAN release and not the version I need.

georgestagg commented 7 months ago

Using this method should indeed load shinyMobile v2.0.0 in webR. The repository list is ordered: your custom repo will be tried first, and the remaining package dependencies will be loaded from the webR repository fallback so as to match CRAN releases.

Screenshot 2024-04-19 at 09 44 48

DivadNojnarg commented 7 months ago

This works on the webR demo (https://webr.r-wasm.org/latest/)

Screenshot 2024-04-21 at 16 57 51

But not on from shinylive.

Screenshot 2024-04-21 at 16 55 24

Trying with incognito mode, clearing browser cache does not change anything.

hypebright commented 7 months ago

There's some strange behaviour in shinylive, my wild guess is that it's something related to timing.

We can make it work, but there are specific steps needed:

  1. Refresh the shinylive page
  2. Run the code without library(shinyMobile) - which encounters an error because it can't find f7Page but that's fine
  3. Add library(shinyMobile) and run it again

This way it is using the 2.0.0:

image

But refreshing the shinylive page and directly using this code (without letting it fail first):

webr::install(
  "shinyMobile",
  repos = c("https://rinterface.github.io/rinterface-wasm-cran/", "https://repo.r-wasm.org")
)

library(shiny)
library(shinyMobile)

app <- shinyApp(
  ui = f7Page(
    title = "Update f7SmartSelect",
    f7SingleLayout(
      navbar = f7Navbar(title = "Update f7SmartSelect"),
      f7Block(f7Button("update", "Update Smart Select")),
      f7List(
        inset = TRUE,
        strong = TRUE,
        outline = TRUE,
        f7SmartSelect(
          inputId = "smartselect",
          label = "Choose a variable:",
          choices = split(colnames(mtcars[-1]), rep(1:5)),
          openIn = "popup"
        )
      ),
      tableOutput("data")
    )
  ),
  server = function(input, output, session) {
    output$data <- renderTable(
      mtcars[, c("mpg", input$smartselect), drop = FALSE],
      rownames = TRUE
    )

    observeEvent(input$update, {
      updateF7SmartSelect(
        inputId = "smartselect",
        openIn = "sheet",
        selected = "hp",
        choices = c("hp", "gear", "carb"),
        multiple = TRUE,
        maxLength = 2
      )
    })
  }
)

app

Will return 1.0.1

georgestagg commented 7 months ago

Thank you both for this great debugging information! I now know what is going wrong.

In Shinylive, there is some startup code to search for dependencies in an app and automatically install them before the app has loaded. With this, users do not need to know about webr::install(). However, the code does not take into account downloading from alternative repositories. I have opened an issue about it here: https://github.com/posit-dev/shinylive/issues/125.

For the moment, while far from ideal, there should be a workaround in removing the automatically installed version of shinyMobile before running webr::install():

webr::unmount("/usr/lib/R/library/shinyMobile")
webr::install(
  "shinyMobile",
  repos = c("https://rinterface.github.io/rinterface-wasm-cran/", "https://repo.r-wasm.org")
)

Workaround example.

Hopefully, we can get this fixed either by introducing some way to list repositories for automatic package download or by making webr::install() installed packages have higher priority.

hypebright commented 7 months ago

Thanks George!