This is a demo repository to demonstrate a GitHub Actions workflow that deploys a Shiny app to ShinyApps.io (using the shinyapps-io-deploy Action).
This is example is part of Workshop: Introduction to GitHub and GitHub Actions, contributed to the 4th QCBS R Symposium on June 23rd, 2022. This workshop is contributed by Pedro Henrique P. Braga (Concordia University) & Katherine Hébert (Université de Sherbrooke).
See the Actions workflow here.
To deploy your Shiny app to RStudio’s ShinyApps.io, you will need to make a ShinyApps.io account. You can sign up with your GitHub account!
To deploy your Shiny app, you will need to generate a Token in your shinyapps.io account.
On the lefthand panel under Account, go to Tokens.
To generate a token, click on the green + Token button.
You should now see a Token, and a Secret (which will be a line of X's). You can reveal the Secret by clicking on the blue Show button on the right.
You will need both the Token and the Secret in the next step.
Secrets are encrypted tokens you can use in your GitHub workflow, usually to grant permission to access and write to your repository (or in this case, to deploy to ShinyApps.io).
To create secrets in your GitHub repository:
- Go to your GitHub repository.
- Click on
Settings, then onSecrets > Actionsin the lefthand panel menu. - Click on
New repository secret.
You will need to make 2 secrets so your workflow can deploy to shinyapps.io:
SECRET: copy the secret from your shinyapps.io token. (Remember, reveal it by clickingShow).TOKEN: copy the token from your shinyapps.io token.
- Create a
gh-pagesbranch in your GitHub repository. - Create a folder named
.githubin your GitHub repository. - Create a subfolder called
workflowswithin the.githubfolder. - Create a new
.ymlfile in this folder (you can open a text file, and save it with the.ymlextension). - Copy the following workflow into your
.ymlfile:
on:
push:
branches:
- main
name: Deploy template app to shinyapps.io
jobs:
deploy-shiny:
name: Deploy to shinyapps.io
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.ACCESS_TOKEN }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
steps:
- name: 🛎️ Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- id: deploy
name: 💎 Deploy to shinyapps.io
uses: qwert666/shinyapps-actions@main
env:
SHINY_USERNAME: 'katherinehebert' # put your own username here!
SHINY_TOKEN: ${{ secrets.TOKEN }}
SHINY_SECRET: ${{ secrets.SECRET }}
APP_NAME: 'myApp' # this will show in the app's url
APP_DIR: ''
To access your deployed Shiny app, go to the following url using your own ShinyApps.io username and the App name you set near the end of the GitHub Actions workflow as APP_NAME.
<SHINY_USERNAME>.shinyapps.io/<APP_NAME>
For example, the app that is deployed here is accessible here: