8

I'm running a R shiny application on an open source shiny-server, using Ubuntu and NGINX. However, my app keeps getting the message "Disconnected from the Server" for some reason and I can't seem to get it to work. The shiny app runs perfectly fine on my local.

I've tried the javascript workaround via the following suggestion in Shiny server session time out doesn't work, but it still doesn't seem to work.

Also tried to set app_idle_timeout and app_init_timeout to a longer duration, but to no avail.

This is my nginx config file:

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;

    server_name some_ip_address;

    location / {
         proxy_pass http://localhost:3838/;
         proxy_redirect http://localhost:3838/ $scheme://$host/;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection $connection_upgrade;
         proxy_read_timeout 20d;
    }

}

Was wondering if I editing shiny server or nginx config file to make this work? But I understand that it is only possible to extend the timeout in the pro version but I'm guessing there must be some workaround possible.

ZPeh
  • 592
  • 1
  • 7
  • 18
  • This error is most likely caused by an error inside the shinyapp, check the shiny logs or go onto your server and just use `runApp` to see of you can reproduce it – Pork Chop Jan 29 '19 at 09:01
  • 1
    @PorkChop Thanks for the suggestion! I've changed the shiny logs and realized that there was a small error within my code which led to this problem. Managed to fix it now – ZPeh Jan 29 '19 at 14:18
  • Glad it worked out, I see the disconnects all the time with `shiny-server` make sure and use `try catch` and `req` where appropriate – Pork Chop Jan 29 '19 at 14:20
  • That looks like an nginx config. Is that really your Shiny Server config, or an nginx config file named shiny-server.conf? – greg L Jan 29 '19 at 15:33
  • @PorkChop Yes, the disconnect with shiny-server is quite annoying, will heed your advice and thank you once again! – ZPeh Jan 31 '19 at 03:04
  • @gregL Yes, apologies this is supposed to be my nginx config file rather than shiny server config file. – ZPeh Jan 31 '19 at 03:05
  • have a look at the js log, right click on the page and click on inspect and see what has stopped the websocket connection between the client and the server – Pork Chop Jan 31 '19 at 08:10

1 Answers1

8

You can disable application idle timeouts in Shiny Server (open source or Pro) by setting app_idle_timeout to 0 in your Shiny Server config file.

For example,

location / {
    app_idle_timeout 0;
}

https://docs.rstudio.com/shiny-server/#application-timeouts

app_idle_timeout -- Defines the amount of time (in seconds) an R process with no active connections should remain open. After the last connection disconnects from an R process, this timer will start and, after the specified number of seconds, if no new connections have been created, the R process will be killed. The default value for app_idle_timeout is 5 seconds.

greg L
  • 4,034
  • 1
  • 19
  • 18
  • Just a heads up, the default Shiny configuration file is located by default at `/etc/shiny-server/shiny-server.conf`, so, to edit the Shiny config file in (in Ubuntu), type: `sudo nano /etc/shiny-server/shiny-server.conf` – Bastián Olea Herrera Jul 06 '23 at 19:19