install.packages("usethis")
Appendix A — Setup for the workshop
Thanks for your interest in the R Shiny workshop. You will need to do the following, outlined below, before the workshop.
- Install R
- Install RStudio
- Install Quarto
- Setup GitHub Account
- Install Git (optional)
- Setup shinyapps.io
- Posit Cloud (optional)
Most of these steps 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.6), although we strongly encourage you to install the software on your personal computer for use after the workshop.
Please reach out if you have any issues with installation: mbeck@tbep.org
A.1 Install R and RStudio
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.1.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.1.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.1.3 macOS: Download and install R
A.1.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.1.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.2 Install Quarto
A visual editor for Quarto is installed with RStudio. However, you’ll need to install Quarto CLI to make full use of its features.
Navigate to https://quarto.org/docs/get-started/. You’ll see a screen that looks like this:
Select the download appropriate for your operating system (Windows is the big blue button). After the file is downloaded, navigate to the folder containing the file, double-click to install, and accept the default settings at the prompts.
After installation is done, open RStudio (or close and open again) and select the Terminal tab. This tab is located on the bottom-left pane, next to the Console tab. Type quarto check
at the prompt and press enter. You should see something like this if installation was successful.
A.3 Create GitHub account
Open a web browser and enter the url https://github.com. On the top-right, you should see a button to sign up. Click the button and register an account by choosing an email, username, and password.
A.4 Install Git (optional)
After you’ve registered a new GitHub account, you can install the Git software on your computer. Git is version control software used by RStudio that allows you to access GitHub. Open the url https://git-scm.com/book/en/v2/Getting-Started-Installing-Git and follow the instructions for your operating system.
After Git is installed, open RStudio (or close and open again) to verify the installation. You should see a new “Git” tab located in the top-right pane of RStudio.
A.4.1 Make sure RStudio can talk to GitHub via Git
The next step can be a bit tricky, but is essential if you want to access your GitHub using RStudio and Git. First, install the usethis
R package in RStudio.
You must let Git know who you are and that you have permission to write to a GitHub repository. First, let Git know who you are, where you enter your user name and email associated with the account from the previous step.
::use_git_config(user.name="Jane Doe", user.email="jane@example.org") usethis
Next, you need to setup a personal access token (PAT) that defines the permissions to write to a repository. This can be done as follows:
::create_github_token() usethis
Then follow the remaining prompts to complete the PAT creation. A more thorough explanation can be found here.
A.5 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.
::setAccountInfo(name='beckmw',
rsconnecttoken='<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.
A.6 Posit Cloud (optional)
Posit Cloud provides an environment to use RStudio and the resources above through a web browser. We’ve created a workspace on Posit Cloud that includes most of the content described above. Open the following URL in a web browser: https://posit.cloud/content/5544370
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.