Why does my app work locally, but not on my Shiny Server?


There are many reasons why an application that appears to work locally may have performance issues or other problems when running on Shiny Server. We recommend starting by checking your application logs for any errors in your application. You can see your application logs by checking your log directory - see here. Note that you may need to set preserve_logs true; in your configuration file to make sure that logs persist even if the application closes.

Here are some common issues that may be responsible:

  • If you’re building your Shiny app on a different machine, your application may be dependent on code or environment variables that are only present in that local environment. Make sure your application is defining any environment variables that need to be set, your application is properly sourcing any external code, and your application folder on the Shiny Server includes all necessary files.
  • Your application may be dependent on packages that are installed and loaded in your environment, but aren’t installed for the correct user on the Shiny Server. Make sure that all necessary packages are installed for the same user set under run_as in your Shiny Server configuration file.
  • Make sure you’ve installed the same versions of all packages on the Shiny Server as you have locally, including the shiny package itself. Differences in packages or dependencies may lead to errors in your code.
  • Using absolute file paths instead of relative paths. For example, the following two examples may fail, especially if they refer to locations on your local machine rather than on the server:
    • Windows: read.csv("C:\myapplication\data\myfile.csv")
    • Linux or Mac: read.csv("~/myapplication/data/myfile.csv")

    Ideally, your application should reference the data file by a path relative to the application, e.g., read.csv("data/myfile.csv"). If not, you should make sure the path given is one that exists on the server and the file in question exists and is readable in that location.

  • Attempting to change the working directory. This is a corollary to the previous item. The working directory is the directory where your ui.R and server.R files reside. If you need to reach files in a subdirectory, you should use relative paths rather than changing the working directory. For example, the following two examples will fail:
    • Windows: setwd("C:\myapplication\data")
    • Linux or Mac: setwd("~/myapplication/data")
  • Attempting to access resources that are not reachable from your Shiny Server
  • Use of packages that require Windows (Shiny Server runs on Linux)
  • Use of packages that require access to the display (e.g., packages that require Tcl/Tk)
  • Your application may be failing when it comes under the load of several users. This could happen for a variety of reasons, including but not limited to:
    • Forgetting to close each database connection after loading in data (the connection limit may be hit)
    • Making multiple long-running calls to a public API (the API request limit may be hit)
    • Sub-optimal application scaling or tuning (see our Troubleshooting applications in Shiny Server article)