Support

Why does my app work locally, but not on shinyapps.io?

Follow

There are many reasons why an application that appears to work locally may have performance issues or other problems when running on shinyapps.io. We recommend starting by checking your application logs for any errors in your application You can see your logs in the shinyapps.io dashboard under the Logs tab in the Application view. Alternatively, you can use the rsconnect::showLogs() function to show the log messages of a deployed application.

Here are some common issues that may be responsible:

  • Your application may be dependent on code or environment variables that are only present in your 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 bundle includes all necessary files.
  • Your application may be dependent on packages that are installed and loaded in your environment, but aren’t included as library() calls in your application. Make sure that you have explicit library() calls in your application for all packages required for your application.
  • Using absolute file paths instead of relative paths. For example, the following two examples will fail:
    • Windows: read.csv("C:\myapplication\data\myfile.csv")
    • Linux or Mac: read.csv("~/myapplication/data/myfile.csv")

    Instead, your application should reference the data file by a path relative to the application, e.g., read.csv("data/myfile.csv"). See the section of our Admin Guide on Storage for more information.

  • 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 shinyapps.io (for example, a database behind your organization’s firewall)
  • Use of packages that require Windows or a non-Linux system (shinyapps.io runs on Linux, specifically Ubuntu)
  • Use of packages that require access to the display (e.g., packages that require Tcl/Tk)
  • Your application may require more resources than are available in the instance or 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 instance or worker provisioning (see the Troubleshooting Performance section of our shinyapps.io admin guide)

If your application displays differently when deployed to shinyapps.io vs when it's local, we would recommend a few different troubleshooting steps.

  1. Test the deployed application in multiple browsers, do you experience the same issue in each browser?
  2. If you resize the windows, does that change anything?
  3. If you view the application locally in a browser on the desktop before deploying, does it look as expected? This can be done by running the app in the IDE and then at the top of the new window, there is an "Open in Browser" button.

Comments