3

I am running a Shiny app on Ubuntu using the free Shiny server. When I view the app in a tab in a browser (on MacOS or iPhone) it works fine. If I leave the tab open for a few minutes and return to the tab, I see the familiar translucent grey overlay with a rectangular box in the lower left stating, "Disconnected from the server. Reload".

There are no error indicated at /var/log/shiny-server/app-name... or at /var/log/shiny-server.log.

Here's my shiny server config file:

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {

    # Defines the amount of time (in seconds) an R process with no active connections should remain open.
    app_idle_timeout 0;

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}

Based on this post, I thought the addition of app_idle_timeout 0; would prevent this from happening. It hasn't.

Running /opt/shiny-server/bin/shiny-server --version results in:

Shiny Server v1.5.14.948

I understand Dean Attali has created, shinydisconnect, as a way to make this message look nicer. However, I am wondering how to prevent this message from appearing at all if no errors have occurred.

ixodid
  • 2,180
  • 1
  • 19
  • 46
  • Related: https://community.rstudio.com/t/keep-shiny-app-running-in-shiny-server-no-greying-out/27784/4 – r2evans Sep 28 '20 at 06:28
  • @r2evans That solution does not work at all on an iPhone. Even with the clock visible, the Shiny app on the iPhone greys out within a few minutes on Firefox, Safari, and Chrome. – ixodid Oct 08 '20 at 23:50
  • Change app_idle_timeout to a large number. Maybe it is making the server instantly timeout – cs641311 Oct 26 '20 at 18:06

1 Answers1

3

The "Disconnected from Server" error is a generic message that means that the R session has shut down for some reason. This could happen for a multitude of reasons, ranging from missing objects, to data that takes too long to load, to the use of forbidden packages, to hitting the application timeout settings.

The first thing you should do when encountering this error is check the application log. This can be accessed in the shinyapps.io dashboard, under the Logs tab in the Application view, or by running rsconnect::showLogs() in the RStudio console. enter image description here

This log will contain information about the startup and running of your application. Any errors encountered along the way will be shown here, comparable to the log created when you run the shiny application locally in your own R process.

It may also help to check the Javascript console in your browser while the application is running, which may show additional errors and messages related to your application. The exact instructions for checking this will vary depending on your browser. enter image description here

If you see errors related to the data, code, or workspace of the application, you will need to fix them before the application will load properly. Remember that applications deployed to shinyapps.io must be independent and self-contained, so all the data, workspace objects, and other resources that the app needs must be deployed with it, or accessible via the internet.

Even if there is no error in the application log, the problem may still lie within your code. There are many resources available online to assist you in debugging and optimizing your app, including our Debugging Shiny Applications article, and the shinyapps-users Google group.

Be aware that your app may run well locally, but fail on shinyapps.io once it comes under load from multiple users. This could happen for a variety of reasons, including but not limited to:

Forgetting to close each database connection after loading in data Making multiple long-running calls to a public API Sub-optimal application instance or worker provisioning Finally, our Scaling and Tuning article describes best practices regarding optimizing the performance of your shinyapps.io application.

Jasar Orion
  • 626
  • 7
  • 26