rstudio / shiny-server

Host Shiny applications over the web.
https://rstudio.com/shiny/server
Other
716 stars 289 forks source link

Start R Process on Shiny Server Startup #450

Closed jdonnell01 closed 4 years ago

jdonnell01 commented 4 years ago

Hello,

I am using shiny server Open Source (https://hub.docker.com/r/rocker/shiny) and I am deploying the app via Kubernetes/Docker. My app begins by pulling RDS files from an S3 object store so initialization of the app takes about 30 seconds, however the objects are stored globally so they are shared between sessions. However, it seems that my R app doesn't initialize until the first time someone hits the app rather than when I push the app and shiny server starts. Can this be changed so the app starts up immediately when shiny server starts rather than when the first user attempts to hit the app?

With the current setup the first user would need to wait ~30 seconds for the app to load and if I increase the number of replicas then this would conceivably happen to the same number of users.

Thank you very much

jcheng5 commented 4 years ago

With the way Shiny Server's config is currently designed, it's not clear how this would work; usually specific applications are not even represented in the config file, only directories where apps might be found, so Shiny Server needs an actual web request to even discover that the app exists.

Could you work around this limitation by using curl to poke your app as part of your docker CMD?

jdonnell01 commented 4 years ago

Hi,

I took your advice and was able to instrument a startup command for my app via Kubernetes:

lifecycle:
            postStart:
              exec:
                command: ["/bin/sh", "-c", "sleep 10; R -e \"httr::GET(paste0(Sys.getenv('HOSTNAME'), ':3838'))\""]

Thanks for the tip!