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?
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)
}
...