rstudio / rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
http://rstudio.github.io/rsconnect/
129 stars 79 forks source link

Deploy shinyapps.io: Timeout but no error in logs #1031

Closed karchjd closed 6 months ago

karchjd commented 6 months ago

My shiny app (https://github.com/karchjd/lavaangui/tree/debug-shinyapp) runs perfectly locally and when I deploy it to https://www.heroku.com/ (https://lavaangui-64ec430ee663.herokuapp.com/#). When I deploy it to shinyapps.io, it deploys it successfully but visiting the webpage (https://solo-fsw.shinyapps.io/lavaangui/) leads to a timeout error:

An error has occurred
Unable to connect to worker after 60.00 seconds; startup took too long. Contact the author for more information.

Note that the app starts within a few seconds max locally and on heroku.

However, I don't get any errors in the logs:

2023-12-20T10:53:48.634361+00:00 shinyapps[10373658]: Starting R with process ID: '32'
2023-12-20T10:53:48.638720+00:00 shinyapps[10373658]: Shiny application starting ...
2023-12-20T10:53:48.642969+00:00 shinyapps[10373658]: Warning in loadSupport(appDir, renv = sharedEnv, globalrenv = NULL) :
2023-12-20T10:53:48.647881+00:00 shinyapps[10373658]:   Loading R/ subdirectory for Shiny application, but this directory appears to contain an R package. Sourcing files in R/ may cause unexpected behavior.
2023-12-20T10:53:48.652196+00:00 shinyapps[10373658]: ℹ Loading lavaangui
2023-12-20T10:53:48.656550+00:00 shinyapps[10373658]: [1] "starting server"
2023-12-20T10:53:48.660974+00:00 shinyapps[10373658]: [1] ""
2023-12-20T10:53:48.665396+00:00 shinyapps[10373658]: 
2023-12-20T10:53:48.669869+00:00 shinyapps[10373658]: Listening on http://127.0.0.1:4220

I deploy my app like this: https://github.com/karchjd/lavaangui/blob/debug-shinyapp/dev/deploy.R

hadley commented 6 months ago

Why is your app starting a server? I think that's the place I'd start.

aronatkins commented 6 months ago

shinyapps.io uses code like the following to run your application:

shiny::runApp(
    host = HOST,
    port = PORT,
    ...
)

The host, port, and a number of other runApp() parameters are determined dynamically when your application starts.

Your start_app() function is calling runApp(), which is unnecessary and becomes a recursive runApp() invocation.

Try having the app.R produce the shinyApp() result rather than starting a server.

karchjd commented 6 months ago

Thanks so much for the fast help!! This solved my problem.

It seems that I got confused by the multiple different ways of deploying an app and forgot that for shinyapps.io, defining the app is sufficient.

aronatkins commented 6 months ago

Happy to help. In the future, the shinyapps.io community forum can also give advice: https://community.rstudio.com/c/shiny/shinyappsio/24