Appendix A — Setup for the workshop

Thanks for your interest in the R Shiny workshop. You can participate during the worskhop in two ways. First, you can use an RStudio project setup on Posit Cloud (preferred) or you can use your own version of R and RStudio on your laptop. The instructions below describe setup for each.

Please reach out if you have any issues with installation: mbeck@tbep.org

A.1 Posit Cloud

Posit Cloud provides an environment to use RStudio through a web browser. It’s useful as a workshop resource because necessary packages and scripts are already included. After the workshop, you’ll want to continue work with R and RStudio installed on your own computer.

We’ve created a workspace on Posit Cloud that includes all of the content for this workshop. Open the following URL in a web browser: https://posit.cloud/content/9569756

You will see a login screen that looks like this:

Sign up using a personal login or existing account (Google, GitHub, etc.).

You’ll see the workspace in your browser once you’ve signed in. You’ll need to make a permanent copy to save your work. Just click the button at the top marked “+ Save as Permanent Copy”. When this is done, the red text at the top indicating “TEMPORARY COPY” will no longer be visible.

Now you can follow along with the workshop content.

A.2 Install R and RStudio

You can also use R and RStudio on your local computer for this workshop. Posit Cloud is setup as a convenience and you will want to work locally with R after the workshop.

Most of the steps below will require administrative privileges on a computer. Work with your IT staff to complete the setup if you do not have these privileges. As an alternative, you can use Posit Cloud to participate (see Section A.1), although we strongly encourage you to install the software on your personal computer for use after the workshop.

R and RStudio are separate downloads and installations. R is the underlying statistical computing software. RStudio is a graphical integrated development environment (IDE) that makes using R much easier and more interactive. You need to install R before you install RStudio.

Thanks to the USGS-R Training group and Data Carpentry for making their installation materials available. The following instructions come directly from their materials, with a few minor edits to help you get set up.

A.2.1 Windows: Download and install R

Go to CRAN and download the R installer for Windows. Make sure to choose the latest stable version (v4.2.3 as of April 2023).

Once the installer downloads, Right-click on it and select “Run as administrator”.

Type in your credentials and click yes (or if you don’t have administrator access have your IT rep install with Admin privileges).

You can click next through the standard dialogs and accept most defaults. But at the destination screen, please verify that it is installing it to C:\Program Files\R

At the “Select Components” screen, you can accept the default and install both 32-bit and 64-bit versions.

At this screen, uncheck ‘Create a desktop icon’ because non-admin users in Windows will be unable to delete it.

A.2.2 Windows: Download and install RStudio

Download RStudio from here.

After download, double-click the installer. It will ask for your administrator credentials to install (you might need to have your IT rep install again).

Accept all the default options for the RStudio install.

A.2.3 macOS: Download and install R

  • Download and install R from the CRAN website for Mac here.
  • Select the .pkg file for the latest R version
  • Double click on the downloaded file to install R
  • It is also a good idea to install XQuartz (needed by some packages)

A.2.4 macOS: Download and install RStudio

  • Go to the RStudio download page
  • Under Installers select the appropriate RStudio download file for macOS
  • Double click the file to install RStudio

A.2.5 Check Install

Once installed, RStudio should be accessible from the start menu. Start up RStudio. Once running it should look something like this:

A.3 Setup shinyapps.io

The shinyapps.io website is a service provided by Posit for hosting Shiny applications online. A free option is available, with additional paid tiers depending on your needs. Although there are other free options, this website is the easiest and quickest way to host a Shiny application.

First, navigate to shinyapps.io and click the “Sign Up” button. After you’ve setup your GitHub account, you can sign up for shinyapps.io by selecting the GitHub sign up option.

Next, install the rsconnect package in R. This package lets you connect to shinyapps.io and push applications from your local computer.

install.packages("rsconnect")

You need to obtain an access token from shinyapps.io to configure the rsconnect package to use your account. In your shinyapps.io dashboard, click your user name on the top right and select Tokens.

Add a new token, copy/paste the command to setup your account info, and execute it in the R console. It will look something like this and there will a button that allows you to copy the command to your clipboard, where <TOKEN> and <SECRET> are specific to your account and should not be shared.

rsconnect::setAccountInfo(name='beckmw',
              token='<TOKEN>',
              secret='<SECRET>')

Now you will be able to push a Shiny application to your shinyapps.io account as follows.

library(rsconnect)
deployApp()

More info can be found here.