3

I have a simple demo app in a demo/app.R file that looks like this:

library(shiny)
library(ggplot2)

ui <- fluidPage(
  titlePanel("GGPlot2 Example in Shinylive"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("n", "Number of points:", 
                  min = 10, max = 1000, value = 100)
    ),
    mainPanel(
      plotOutput("ggplot")
    )
  )
)

server <- function(input, output, session) {
  output$ggplot <- renderPlot({
    df <- data.frame(x = rnorm(input$n), y = rnorm(input$n))
    ggplot(df, aes(x = x, y = y)) + 
      geom_point(color = "steelblue") + 
      theme_minimal()
  })
}

shinyApp(ui = ui, server = server)

I deploy it using this line:

shinylive::export("demo", "demo_site")

and then run this line:

httpuv::runStaticServer("demo_site")

The app then tried to load in my browser but I get this error message:

An error has occurred!
package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called ‘munsell’

also if I 'inspect' and look in the console I see lines like this:

Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.Understand this error.

shinylive.js:32076 WebR is using `PostMessage` communication channel, nested R REPLs are not available.

tn @ shinylive.js:32076Understand this warning
shinylive.js:35463 preload error:wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
_error @ shinylive.js:35463Understand this error
shinylive.js:35463 preload error:falling back to ArrayBuffer instantiation

shinylive.js:35463 preload error:Warning: Error in : package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):

shinylive.js:35463 preload error:Warning: Error in : package or namespace load failed for ‘ggplot2’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):

It looks like it isn't bundling my dependencies. It deploys fine if I just use a basic demo using baseR graphics like this.

Is there some other step I need to take if I want to deploy the app using shinylive and extra dependencies such as ggplot2?

2
  • Your MRE works fine in shinylive.io/r Have you tried updating your version of ggplot2 and all it's dependencies? I've also checked and {munsell} is available for webR. You should be getting some errors when you run shinylive::export() that might help diagnose Commented Jun 25 at 8:42
  • I didn't know about shinylive.io/r but yes it does seem to work in there. I just updated my version of R (I was on 4.4.1, now on 4.5.1) I have installed the latest version of ggplot2, shiny and shinylive etc and I still have the same problem. Also no errors from shinylive::export(). It seems like it should be a reasonably straight forward example. Commented Jun 25 at 9:23

1 Answer 1

5

This seems to be a known issue - https://github.com/r-wasm/webr/issues/537 .
As a workaround, adding library(munsell) would include explicit munsell dependency, example at R package availability uses unreachable code block for this.
E.g. try with something like:

library(shiny)
library(ggplot2)

if (FALSE) {
  library(munsell)
}
...
Sign up to request clarification or add additional context in comments.

5 Comments

It now works, but the fix makes no sense to me. I tried the library(munsell) fix but I got the same error message. Then I remade the app to use only dplyr, shiny and baser plotting and it worked. Then I added in plotly into the mix and it also worked. Then I went back to my original app but with shiny, ggplot2 and munsell (as per the solution above) and it worked. The I removed library(munsell) and now my original code works! So I don't really know what to mark as the answer here but thanks for your help, it got me there in a roundabout way.
By any chance, did you use the same demo_site destdir for all your app exports, shinylive::export("demo", destdir = "demo_site") ? export() doesn't remove existing webr packages from destdir, once munsell package was fetched, it still remained there when you removed the dependency from code and re-exported. You can check demo_site/shinylive/webr/packages/ for a list of packages in your current deployment.
Though I have no idea why shinylive attempts to load munsell in the first place, it's just suggested dependency of ggplot2 and in shiny the app works fine when testing in a renv environment where munsell in not installed.
Also, somewhere in all of those steps I think I also deleted the demo_site folder so that may have cleared out some problematic files.
That's a great point about using the same folder. I just deleted the 'demo_site' folder and tried to export and it didn't work. Actually this time the browser window just came up blank but when I inspected it I could see in the console that it couldn't load 'ggplot2' or 'munsell'. When I added 'library(munsell)' back in (after again deleting the 'demo_site' folder) it exported correctly . So although it didn't work straight away that is indeed a valid fix or at least part of it. I have marked the answer correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.