Support

Troubleshooting Deployments

Follow

This article answers frequently asked questions on deploying to RStudio Connect. Also see: 

 

Setting up an account

I am getting an error that Connect does not appear to be running.

Double check that you specified the correct URL for your Connect server, and that you’re using the appropriate http or https prefix. If your server is using SSL, ensure you have the latest version of the rsconnect package (see “SSL Error” below).

In some cases this error can occur if you’re running RStudio Server and RStudio Connect on the same machine and you’re using an http(s) proxy. Try disabling the http proxy by setting the environment variables http_proxy and https_proxy to "" and then connecting your account.

For more detailed output, directly use the rsconnect functions addServer() and connectUser() instead of using the IDE’s publishing interface.

I am getting an SSL error.

This is likely a result of an old rsconnect package installation.  More recent development of the rsconnect package has improved the handling of self-signed SSL certificates.  You can see what version you have installed with packageVersion("rsconnect"), and install the latest with devtools::install_github("rstudio/rsconnect").  In particular, please be sure you have an rsconnect version greater than 0.8.6.

 

Deployment Failures
 

Can I get more information about why a deployment failed?

Yes, you can turn on verbose logging by going to Tools -> Global Options -> Publishing and selecting "Show diagnostic information when publishing". 

A sample deployment log is provided below. Note the steps in bold.

----- Deployment log started at  2018-02-22 15:19:51  -----
Deploy command: 
 rsconnect::deployApp(appDir = "~/Documents/Sandbox/app",      appFileManifest = "/var/folders/vz/140flhsd3r19hgdszzgb4sv40000gn/T/d5d9-91f5-1e5b-4653",      account = "sean", server = "example.connect.com",      appName = "app", appId = 37, ...

Session information: 
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.6

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] rsconnect_0.8.7
Cookies: 
[1] "None"
GET /__api__/applications/37 438ms
----- Bundle upload started at  2018-02-22 15:19:52  -----
[2018-02-22 15:19:52] Inferring App mode and parameters 
[2018-02-22 15:19:52] Bundling app dir 
[2018-02-22 15:19:52] Generate manifest.json 
[2018-02-22 15:19:57] Writing Rmd index if necessary 
[2018-02-22 15:19:57] Compressing the bundle 
POST /__api__/applications/37/upload 1551ms
[2018-02-22 15:19:59] Saving deployment record for goldilocks-app2 - sean 
----- Server deployment started at  2018-02-22 15:19:59  -----
POST /__api__/applications/37/deploy 370ms
<< {
	"bundle" : 65
}
GET /__api__/tasks/UpW3fuArWaMBjPtx?first_status=0 310ms
Building Shiny application...
Bundle requested R version 3.3.3; using /opt/R/3.3.3/bin/R which has version 3.3.3
2018/02/22 22:19:59.776876026 # Validating R library read / write permissions --------------------------------
GET /__api__/tasks/UpW3fuArWaMBjPtx?first_status=3 705ms
2018/02/22 22:19:59.895361172 # Validating packrat installation ----------------------------------------------
2018/02/22 22:19:59.895468513 Installed packrat SHA is: 4b3e4025404f98d25fb73799e86c1762effe5d7e
2018/02/22 22:19:59.895582097 Packaged packrat SHA is:  4b3e4025404f98d25fb73799e86c1762effe5d7e
2018/02/22 22:19:59.896771639 Packrat is up-to-date.
2018/02/22 22:19:59.896906557 R version: 3.3.3
2018/02/22 22:19:59.896921797 packrat version: 0.4.8.52
2018/02/22 22:19:59.897498721 # Validating packrat cache read / write permissions ----------------------------
2018/02/22 22:20:00.081439023 Audited package hashes with local packrat installation.
2018/02/22 22:20:00.086814930 # Installing required R packages with `packrat::restore()` ---------------------
2018/02/22 22:20:00.347932538 Installing BH (1.65.0-1) ... 
2018/02/22 22:20:00.371367223 Using cached BH.
2018/02/22 22:20:00.372168994 	OK (symlinked cache)
2018/02/22 22:20:00.372381400 Installing MASS (7.3-45) ... 
2018/02/22 22:20:00.394135977 Using cached MASS.
2018/02/22 22:20:00.394957004 	OK (symlinked cache)
2018/02/22 22:20:00.395171383 Installing R6 (2.2.2) ... 
2018/02/22 22:20:00.415667151 Using cached R6.
2018/02/22 22:20:00.416492213 	OK (symlinked cache)
2018/02/22 22:20:00.416711605 Installing RColorBrewer (1.1-2) ... 
2018/02/22 22:20:00.436793491 Using cached RColorBrewer.
2018/02/22 22:20:00.437583769 	OK (symlinked cache)
2018/02/22 22:20:00.437799608 Installing Rcpp (0.12.14) ... 
2018/02/22 22:26:19.839741769 	OK (symlinked cache)
Completed packrat build against R version: '3.3.3'
Launching Shiny application...
GET /__api__/applications/37/config 224ms
----- Deployment log finished at  2018-02-22 15:26:21  -----
Deployment completed: https://connect.example.com/connect/#/apps/37

 

In order to determine more specifically what problem you are experiencing and how to resolve it, you should use the highlighted / bolded steps as pointers to where the deployment is failing. Below, you can explore some common issues and their solutions.


Deployment Failures Before Server Deployment Begins

Failures in this section occur on the client machine, usually where the RStudio IDE is running, and NOT on the RStudio Connect server.  

I'm getting an error: "Unable to retrieve package record". What should I check?

This error can occur if the package is not installed on the computer where RStudio is running.  The solution in that case is to install.packages("packagename").

This error can also occur if the package is not available at the current options("repos") location(s). During the preparation for the publishing process, RStudio will look for the packages in order to build the package dependency manifest.  As a result, it is important to ensure that options("repos") is accessible from the local RStudio environment, and that the package in question is available at this location.


Can I access the bundle Connect attempted to deploy?
 

Yes, there are two ways to get more information about what Connect attempted to deploy. If the deployment was partially successful, you can download the bundle from Connect. Navigate to the desired content (Admin -> Unpublished Content) and the click the “… “button in the upper right corner, above the content settings panel. Select “Source Versions”, pick the deployment of interest, and click “Download”. For more information on the bundle, see: Bundle Downloads.

If the the deployment failed before the bundle was uploaded, you can get information by running the following command inside the content directory:

packrat::.implSnapshot(".", snapshot.sources = FALSE)

This command will create a folder named packrat inside of the content directory. The packrat folder will include the packrat.lock file. This file lists important information about what packages dependencies were identified, what version of R is in use, and what repos are currently available. See the section on Package Dependencies below.

 

Deployment Failures After Server Deployment Begins

Failures in this section occur on the RStudio Connect server.

I received an error message that a package could not be installed. What should I do next?

It can be helpful to get more information by turning on Tools -> Global Options -> Publishing -> "Show diagnostic information when publishing".  Once this is enabled, you should get a bit more verbosity in the publishing process, which can highlight some issues. For instance, if you are missing system dependencies, an admin will need to install those dependencies on the Connect server.  

Another common problem is RStudio Connect not being able to find the package.  When this happens, it is important to be sure that the RStudio Connect server is able to access the repos that are defined locally in options("repos"), and that the desired package is available at those locations.  This is a particularly common issue when RStudio Connect is in an offline environment.

Once you have more detailed logging, the sections below and specifically those on Package Dependencies should be helpful to debugging your specific issue.

 

The deployment log looks successful, but my application is showing an error message. What should I do?

RStudio Connect displays the application logs in an accessible fashion within the UI.  Click the gear icon in the upper right-hand corner of the page and then open the “Logs” tab.  The application logs will be displayed within the UI and can be downloaded for convenience. They should give you some direction as you investigate why your application is displaying an error message.  If the logs prove unhelpful, you can also have an admin take a look at the Connect server log, which is located at /var/log/rstudio-connect.log.


What version of R will be used for my content on the Connect server?

By default, RStudio Connect attempts to find an R installation that is appropriate for your content. By default, it applies a “nearest-matching” approach. This algorithm attempts to find a version of R to use with your content. Many deployments will succeed but not always with the same version of R that is used by the author. However, you can control the matching mechanism, with the option of matching “exact”, “major-minor”, or “nearest”. You can find the full description of these options in the R Version Matching section of the RStudio Connect Admin Guide

The deployment log will include a line identifying the version of R in use on the client and the version of R used by the server, e.g., 

Bundle requested R version 3.3.3; using /opt/R/3.3.3/bin/R which has version 3.3.3

 

My R markdown document has other language code chunks. Will it work on Connect?

Yes, on the condition that your system administrator installed these languages and any necessary dependencies or libraries on the server that hosts Connect.  It is important to note that in the latest version of Connect (1.5.14 at the time of writing), no dependency management is done for other languages in the way that is done for R.  As a result, a system administrator must take care of these dependencies.

 

My deployment log suddenly ends, is my content deployed?

There are two likely reasons a deployment log ends abruptly. The first is that the connection between the client and Connect failed. This failure can occur in RStudio Connect clusters that use a cookie-based sticky load balancer. If you see the error “unable to parse cookies” it is likely that your content did deploy successfully, but the deployment log failed. Navigate to RStudio Connect and check the content listing page and the unpublished content listing page (Admin -> Unpublished content).

The second reason a deployment log can end abruptly is if RStudio Connect is unable to start R. This failure occurs most frequently if you’re attempting to use PAM sessions or a program supervisor. Double check that these configurations are correct.

 

I am getting "Error in getSourceForPkgRecord", and am using a local repo and an internal package.

Packages on CRAN have a Repository: CRAN field added to the package’s DESCRIPTION file. This is easy to miss when developing an internal package, however it is essential that the Repository field match up with the output of options("repos").  For instance, if options("repos") returns CRAN = "https://cran.rstudio.com" and myorg = "https://myrepo.myorg.com", where https://myrepo.myorg.com is my company’s local repository, it is important that the internal package has Repository: myorg set in its DESCRIPTION file.  Since this is important for all users of the package, it is best if you establish a precedent / standard within your company and set this value consistently for all internal packages in your local repository and for all developer workstations.

 

Package Dependencies 

Where does Connect look for packages?

Connect runs R, so to understand where “Connect” looks for packages, you must understand where R looks for packages. R stores the repository location in the global options, and you can query this location by using: getOption("repos")

You can set this option using something like: options(repos = c(CRAN = "https://cran.rstudio.com")). For more information on setting this option for a project, or system-wide, see the R help for ?Startup

Connect uses the repo options configured on the computer you are publishing FROM, so setting the value on the Connect Server will not have any effect.  By setting the options("repos") value in your development environment (likely on a desktop or on RStudio Server), you will direct where RStudio Connect should look for packages during the publishing process.

I have a package I know Connect won't be able to install automatically. Can I manually install a package on the Connect server?

Yes, you can manually install a package onto the Connect server. To do so, install the package into the system library for every R installation on the server, and then add the package to the Connect Whitelist; more specific guidance is available in the admin guide.  Be at aware that whitelisting a package prevents Connect from managing different versions of that package; all content on Connect will use the same version of the package.

I am getting a 404 error in the package installation section. What is wrong?

This means that the Connect server cannot find the packages it is trying to install.  In the section above on “Where does Connect look when installing packages?”, we highlight that Connect uses the options("repos") value from the client when looking for packages.  As a result, you should be sure that the output of options("repos") is accessible to the Connect server.  You can set the value using something like: options(repos = c(CRAN = "https://cran.rstudio.com")) prior to deploying to Connect.

In some environments, a proxy is set up between the server and internet. In order to access the internet, Connect must be configured to the use the proxy.  If the address of the proxy is http://myproxy.mycompany.com, then you have a few options for how to configure the Connect server.

The easiest option is to specify the [Packages].HttpProxy and [Packages].HttpsProxy values in the RStudio Connect configuration file. Documentation is available in the admin guide. This configuration ensures Connect will use the proxy when it installs packages. 

If your deployed content also needs access to the internet, you will need to be sure the http_proxy and https_proxy environment variables are set before Connect launches R. There are a few ways to do this: one option is to set the following environment variables in the Renviron.site file for each R installation (located at $R_HOME/etc for each R installation):


http_proxy=http://myproxy.mycompany.com
https_proxy=https://myproxy.mycompany.com


To test this configuration, you can log in as the rstudio-connect user and try to reach the internet or install packages from a given repository.

su -s /bin/sh rstudio-connect
R
options(repos = c(CRAN = "https://cran.rstudio.com"))
install.packages("ISLR")

If your Connect server is entirely offline, then you will need to set up an internal CRAN-like repository containing the packages used by your organization. You can setup this repository manually, you can rsync all of CRAN, you can use a tool like miniCRAN, or you can consider RStudio Package Manager.

What if my code depends on a local package I installed from our internal Git server?

The RStudio Connect admin guide contains detailed instructions for using internal packages with Connect. There are 3 primary options:

1) Install the package manually on Connect and add it to the whitelist. This is the easiest option, but requires all content on Connect to use the same version of the internal package.

2) Set up an internal repository (see the instructions immediately before this question). Once the internal package is accessible from the internal repo, re-install the package on the client and then deploy to Connect. Setting up an internal repo is the best practice for sharing internal packages.

3) Manually add the package to Connect’s [Server].SourcePackageDir using the package’s commit hash. This option is the most difficult and should be used as a last resort.

My instance of RStudio Connect is offline. What can I do?

If you are administering RStudio Connect in an offline environment, you’ll need to follow certain steps to ensure the R packages used by your team are available in Connect. These steps are different from the process you might have used in the past to provide packages to RStudio.

You will need to setup an internal CRAN-like repository containing the packages used by your organization. You can setup this repository manually, you can rsync all of CRAN, you can use a tool like miniCRAN, or you can consider RStudio Package Manager.

Which user account installs R packages? Can I run any tests as this user?

The RStudio Connect RunAs user will run the R process responsible for installing packages. By default, this user is the unprivileged user named rstudio-connect created when RStudio Connect is installed.

To run tests as the rstudio-connect user, run: su -s /bin/sh rstudio-connect

 

Supporting Data, Files, and Databases

Can I reference files from other directories?

You can reference files in subdirectories by using relative paths. For example:

readr::read_csv("./data/data.csv")

You can also reference files in other directories using absolute paths, as long as the directory will also exist on RStudio Connect. A warning message will be issued if absolute paths are used. For example:

readr::read_csv("/app-data/data.csv")

In the case where a data file has one path on your local system and a different path on Connect, use the config package to switch the path at runtime.

 

Can I publish content that uses a database?

Of course.  In fact, this is one of our recommended best practices for building content that scales well.  The resources at http://db.rstudio.com share many of our best practices for using databases with R.  In particular, the articles about securing deployed content , securing credentials , and making scripts portable are highly relevant to users deploying content to Connect.  

 

Automated Deployment

Can I deploy content programmatically?

Yes; refer to the Continuous Integration appendix of the RStudio Connect admin guide. A sample repository deployed to Connect using Travis is available here, and an experimental utility for programmatically promoting code from one server to another is available here.

 

How can I deploy other types of content?

Check out this article to learn about deploying static content like pdfs, bookdown books, blogdown sites, and pkgdown documentation.

Comments