As of version 1.4.4 of RStudio Connect, collaborators on content can manage and download content bundles. This article describes how to use the downloaded bundle.
The downloaded bundle is a compressed tarball. Uncompressed, the bundle contains application code, a manifest file, an html file, and a packrat folder with a packrat.lock file. The bundle can include additional files such as datasets, css, and other R or R Markdown documents.
Opening the Bundle in RStudio
After uncompressing the bundle, we recommend creating a project from the bundle folder:
After opening the bundle there are two options:
- Run the application code as-is. The code will use your default package libraries.
- Restore the packages as they existed on the server.
To restore the packages, use the packrat restore function:
R > # ensure you have the correct working directory R > setwd("path/to/bundle") R > # require packrat R > requireNamespace('packrat') R > # run packrat restore R > packrat::restore()
WARNING Running packrat restore will install all of the packages use by the application. The packrat.lock file lists which packages and versions will be installed.
The packages are installed in a subdirectory of the packrat folder. To ensure R uses this subdirectory when running the application turn packrat on:
R > # turn on packrat R > packrat::on() R > # verify the library location R > libPaths()
Using packrat restore ensures the package versions are correct on the local machine. It can be important to match the version of R as well. The manifest file includes the version of R used by the application:
R > # require the jsonlite library R > requireNamespace(jsonlite) R > # read the manifest file R > manifest <- jsonlite::read_json("manifest.json") R > #print the version of R R > print(manifest$platform)
Deploying Content to RStudio Connect
An opened bundle can be deployed to RStudio Connect in the same way as regular code. However, be aware:
- If you are the original content owner, you can update the application deployed on Connect. Overwrite the existing content by publishing to the same server and account using the same content title. To deploy the content to a new location, specify a different title.
- If you are not the original content owner, you can not update the existing application. You can publish the application to the same server or to a different RStudio Connect instance.
In addition, it is now possible to deploy a bundle using the Connect API! Please follow the steps described here.
Shiny Server (Pro)
It is possible to move Shiny applications or R Markdown documents from RStudio Connect to Shiny Server (Pro). Users should already be familiar with deploying content to Shiny Server Pro.
For Shiny Server (Pro) configurations using site_dir or user_dir, run the following restore script and move the resulting folder to the directory hosted by Shiny Server (Pro). The script requires the R package packrat be installed.
bash$ sh restore.sh /path/to/bundle.tar.gz name_of_app
bash$ cp -r name_of_app /path/to/hosted/directory
echo "Unpacking $1 ..." echo "Making destination directory $2"
mkdir $2 echo "Uncompressing bundle ... "
tar xvzf $1 -C $2 echo "Running R to restore packages..."
Rscript -e "requireNamespace('packrat'); packrat::restore()" --verbose echo "Updating .Rprofile"
echo "# added during bundle restore" >> .Rprofile
echo "requireNamespace('packrat')" >> .Rprofile
echo "packrat::on()" >> .Rprofile echo "Done! Move the $2 directory to the appropriate folder."
echo "Update the Shiny Server (Pro) config file as necessary."
If you are using app_dir, or your application requires additional access controls, you will need to modify the Shiny Server (Pro) configuration file as appropriate.
RStudio Connect and Shiny Server (Pro) should run on servers with the same operating system and matching system libraries. The restore script above only restores the R packages needed by the application. Many R packages rely on system libraries which may need to be installed separately.
If you support multiple versions of R, you should ensure the application runs on the correct version in Shiny Server (Pro). To do so:
- From within the restored bundle, view the version of R used by the application:
bash$ head manifest.json | grep platform
- Use the r_path option in the Shiny Server Pro configuration file to set the version of R used by the application.