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

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

Open
DivadNojnarg opened this issue Apr 12, 2024 · 7 comments
Open

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

DivadNojnarg opened this issue Apr 12, 2024 · 7 comments

Comments

@DivadNojnarg
Copy link

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 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: BristolMyersSquibb/webr-repos@d05444f). 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
Copy link
Member

georgestagg commented Apr 18, 2024

As discussed in #15 (comment), 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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

DivadNojnarg commented Apr 21, 2024

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
Copy link

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
Copy link
Member

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: posit-dev/shinylive#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
Copy link

Thanks George!

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

3 participants