Search code examples
shinyshinyapps

Unable to publish shinyapp on shinyapps.io


I am desperately trying to publish my app on shinyapps.io. My app runs perfectly on my local RStudio, but when I try to publish it, this error message keeps appearing on the browser:

An error has occurred

The application failed to start.

exit status 1

Here is the link where the app should be published, and where the error keeps appearing

This is how the app should look like

I followed every step proposed by shinyapps.io and Stackoverflow, like commenting libraries and paths. I have read that working on a Mac as I do could cause these kind of problems.

Any help would be very appreciated, as I need to publish several apps in order to pass my course!

Here is my code:


dat <- read_csv(url("https://www.dropbox.com/s/uhfstf6g36ghxwp/cces_sample_coursera.csv?raw=1")) %>%
select(c("pid7","ideo5")) %>% drop_na()

ui <- fluidPage(

sidebarLayout(
sliderInput(inputId = "ideo5",
label = "Select Five Point Ideology (1=Very liberal, 5=Very conservative)",
min = min(dat[,2]),
max = max(dat[,2]),
value = 3),

plotOutput("distPlot")

)
)

server <- function(input, output) {

output$distPlot <- renderPlot({

c <- ggplot(dat %>% filter(ideo5 == input$ideo5), aes(pid7)) + labs(x = "7 Point Party ID, 1=Very D, 7=Very D")
c + geom_bar()

})
}
shinyApp(ui = ui, server = server)

Edit: It turned out that not mentioning the libraries in the code was causing the issue! What I added:

library(shiny)
library(tidyverse)
library(ggplot2)

Solution

  • There are a variety of reasons that an app may work locally but not on shinyapps.io. I recommend reading this article for details: https://support.rstudio.com/hc/en-us/articles/229848967-Why-does-my-app-work-locally-but-not-on-shinyapps-io-.

    The first place you want to check is the application log, to see if there are any errors when the shinyapps.io service attempted to start your application - this is the best way to start your investigation.

    The most common causes of an app that works locally but not on shinyapps.io include: use of Windows-specific R packages, missing library() statements in the code, packages that are loaded into your local global environment but not in the application context, and using packages that require system dependencies that are not on the shinyapps.io servers by default. Please see these sections of the users' guide for additional information on these scenarios:

    https://docs.rstudio.com/shinyapps.io/getting-started.html#using-your-r-packages-in-the-cloud https://docs.rstudio.com/shinyapps.io/applications.html#debugging-your-application https://docs.rstudio.com/shinyapps.io/Troubleshooting.html https://docs.rstudio.com/shinyapps.io/appendix.html#default-system-packages

    If you are not using a Windows-based R package, or a package that requires a system dependency that is not on the system, and if you have library() statements in your code for all packages in use, the most common issue is that the packages are not loaded into the application context. When you publish an application to shinyapps.io, the process creates a manifest listing the version of R and of all the packages with library() statement in your code, so it can recreate your environment on the shinyapps.io servers.

    It can't "see" the packages that weren't loaded into the app context since it expects the application to be independent and self-contained; your global environment is not available to it. The easiest way to resolve this kind of issue is to:

    Open the IDE and set the working directory to the application directory Clear the global environment and restart R Re-install all of the packages your application uses Run the app locally to make sure it works Publish to shinyapps.io

    If it fails, first look at the deployment log in the Deploy pane in the IDE. Are there any errors, and can you tell how to fix what went wrong? If the deployment succeeded but the app won't start, take a look at the application log - can you tell what stopped it from starting up successfully? (The app log can be accessed from the shinyapps.io dashboard or by running rsconnect::showLogs() from within the RStudio console.)

    If you are still having trouble after you have fixed any warnings and errors in the log, you can check the memory usage in the shinyapps.io dashboard to make sure you are not exceeding the memory allocation on your application instance. Then, read through the "Debugging your application" section of the users' guide linked above to add logging statements in strategic places in the code to see where the problem lies.