├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── deploy.R /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # User-specific files 9 | .Ruserdata 10 | 11 | # Example code in package build process 12 | *-Ex.R 13 | 14 | # Output files from R CMD build 15 | /*.tar.gz 16 | 17 | # Output files from R CMD check 18 | /*.Rcheck/ 19 | 20 | # RStudio files 21 | .Rproj.user/ 22 | 23 | # produced vignettes 24 | vignettes/*.html 25 | vignettes/*.pdf 26 | 27 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 28 | .httr-oauth 29 | 30 | # knitr and R markdown default cache directories 31 | *_cache/ 32 | /cache/ 33 | 34 | # Temporary files created by R markdown 35 | *.utf8.md 36 | *.knit.md 37 | 38 | # R Environment Variables 39 | .Renviron 40 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # start from shiny-verse to include both the shiny and tidyverse packages, 2 | # saving us time assuming that the app to be deployed doesn't have dependencies 3 | # locked to different versions. 4 | FROM rocker/shiny-verse:latest 5 | 6 | # install rsconnect and renv packages, as well as prerequisite libraries 7 | RUN apt-get update && apt-get install -y \ 8 | libssl-dev \ 9 | libcurl4-openssl-dev 10 | RUN install2.r rsconnect renv 11 | 12 | # copy deploy script to root of the workspace 13 | COPY deploy.R /deploy.R 14 | 15 | # run deploy script, ignoring any .Rprofile files to avoid issues with conflicting 16 | # library paths. 17 | # TODO: this may cause issues if the .Rprofile does any setup required for the app to run 18 | CMD ["Rscript", "--no-init-file", "/deploy.R"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 BDSI, University of Twente 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # shinyapps-deploy-github-action 2 | 3 | GitHub action to automate deployment of shiny applications on . 4 | 5 | ## Example 6 | 7 | ```yaml 8 | name: Deploy to shinyapps.io 9 | on: 10 | 11 | # run on any push 12 | push: 13 | 14 | # run on request (via button in actions menu) 15 | workflow_dispatch: 16 | 17 | jobs: 18 | deploy: 19 | name: Deploy to shinyapps 20 | 21 | # allow skipping deployment for commits containing '[automated]' or '[no-deploy]' in the commit message 22 | if: "!contains(github.event.head_commit.message, '[automated]') && !contains(github.event.head_commit.message, '[no-deploy]')" 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v2 26 | - name: deploy 27 | uses: BDSI-Utwente/shinyapps-deploy-github-action@v1 28 | with: 29 | # account and application name (https://.shinyapps.io/) 30 | appName: your-application-name 31 | accountName: your-account-name 32 | 33 | # token and secret obtained from https://www.shinyapps.io/admin/#/tokens 34 | accountToken: ${{ secrets.SHINYAPPS_TOKEN }} 35 | accountSecret: ${{ secrets.SHINYAPPS_SECRET }} 36 | ``` 37 | 38 | ## Inputs 39 | 40 | ### Required inputs 41 | 42 | #### appName 43 | 44 | 45 | name of the application (typically the last part of the url, e.g. https://\.shinyapps.io/\). 46 | 47 | 48 | #### accountName 49 | 50 | 51 | account name on shinyapps.io (typically the first part of the url, e.g. https://\.shinyapps.io/\). 52 | 53 | 54 | #### accountToken 55 | 56 | access token, see . Generating a new token/secret pair for this action is recommended, so that you can revoke it without affecting other deployments. 57 | 58 | #### accountSecret 59 | 60 | token secret, see . Generating a new token/secret pair for this action is recommended, so that you can revoke it without affecting other deployments. 61 | 62 | ### Optional inputs 63 | 64 | #### appDir 65 | 66 | _[optional]_ 67 | Path to app, relative to repository root. Defaults to `/`, the repository root. 68 | 69 | #### appFiles 70 | 71 | _[optional]_ comma separated list of files to publish, relative to `appDir`. Overrides `appFileManifest`. If neither `appFiles` or `appFileManifest` are provided, all files in appDir will be published. 72 | 73 | example: `app.R,ui.R,server.R,www` 74 | 75 | #### appFileManifest 76 | 77 | _[optional]_ path to manifest file, relative to `appDir`. Overridden by `appFiles`. The manifest file should contain a list of files to be deployed, one file per line, relative to `appDir`. 78 | 79 | #### appTitle 80 | 81 | _[optional]_ user-friendly title for the application 82 | 83 | #### logLevel 84 | 85 | _[optional]_ level of verbosity of rsconnect::deployApp(). Defaults to `normal`, other options are `quiet` or `verbose`. 86 | 87 | ## Packages 88 | 89 | This action uses the rocker/shiny-verse:latest docker image as a base. This image includes recent versions of most package commonly used in shiny apps and the tidyverse. 90 | 91 | If an `renv.lock` file is present in the repository root, `renv::restore()` will be called to install the specific versions of packages recorded in the lockfile. If no lock file is found, `renv::hydrate()` is used to detect used packages and install any missing packages. Note that in the latter case, the most recent versions of packages will be installed. 92 | 93 | We highly recommend using renv to manage dependencies. 94 | 95 | ## Contributing 96 | 97 | Any contributions are appreciated. In particular, we would appreciate help implementing the following; 98 | 99 | - support for packrat, other R environment management packages 100 | - support for generic rsconnect servers in addition to shinyapps.io 101 | - support for caching of dependencies 102 | 103 | ## References 104 | 105 | This action was inspired by . 106 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Deploy to shinyapps.io" 2 | description: "Deploy R shiny apps to shinyapps.io." 3 | branding: 4 | icon: cast 5 | color: blue 6 | inputs: 7 | appDir: 8 | description: path to app, relative to repository root. Defaults to the repository root. 9 | required: false 10 | appFiles: 11 | description: comma separated list of files to publish, relative to appDir. If not provided, all files in appDir will be published. 12 | required: false 13 | appFileManifest: 14 | description: path to manifest file, listing files to be deployed relative to appDir. 15 | required: false 16 | appName: 17 | description: name of the application (typically the last part of the url, e.g. https://.shinyapps.io/). 18 | required: true 19 | appTitle: 20 | description: user-friendly title for the application 21 | required: false 22 | logLevel: 23 | description: level of verbosity of rsconnect::deployApp(). Defaults to "normal", other options are "quiet" or "verbose". 24 | required: false 25 | default: normal 26 | accountName: 27 | description: account name on shinyapps.io (typically the first part of the url, e.g. https://.shinyapps.io/). 28 | required: true 29 | accountToken: 30 | description: access token, see https://www.shinyapps.io/admin/#/tokens. Generating a new token/secret pair for this action is recommended, so that you can revoke it without affecting other deployments. 31 | required: true 32 | accountSecret: 33 | description: secret, see https://www.shinyapps.io/admin/#/tokens. Generating a new token/secret pair for this action is recommended, so that you can revoke it without affecting other deployments. 34 | required: true 35 | runs: 36 | using: docker 37 | image: Dockerfile 38 | 39 | -------------------------------------------------------------------------------- /deploy.R: -------------------------------------------------------------------------------- 1 | .libPaths("/usr/local/lib/R/site-library") 2 | cat("loading packages from:", paste("\n - ", .libPaths(), collapse = ""), "\n\n") 3 | 4 | # use renv to detect and install required packages. 5 | if (file.exists("renv.lock")) { 6 | renv::restore(prompt = FALSE) 7 | } else { 8 | renv::hydrate() 9 | } 10 | 11 | # set up some helper functions for fetching environment variables 12 | defined <- function(name) { 13 | !is.null(Sys.getenv(name)) && Sys.getenv(name) != "" 14 | } 15 | required <- function(name) { 16 | if (!defined(name)) { 17 | stop("!!! input or environment variable '", name, "' not set") 18 | } 19 | Sys.getenv(name) 20 | } 21 | optional <- function(name) { 22 | if (!defined(name)) { 23 | return(NULL) 24 | } 25 | Sys.getenv(name) 26 | } 27 | 28 | # resolve app dir 29 | # Note that we are likely already executing from the app dir, as 30 | # github sets the working directory to the workspace path on starting 31 | # the docker image. 32 | appDir <- ifelse( 33 | defined("INPUT_APPDIR"), 34 | required("INPUT_APPDIR"), 35 | required("GITHUB_WORKSPACE") 36 | ) 37 | 38 | # required inputs 39 | appName <- required("INPUT_APPNAME") 40 | accountName <- required("INPUT_ACCOUNTNAME") 41 | accountToken <- required("INPUT_ACCOUNTTOKEN") 42 | accountSecret <- required("INPUT_ACCOUNTSECRET") 43 | 44 | # optional inputs 45 | appFiles <- optional("INPUT_APPFILES") 46 | appFileManifest <- optional("INPUT_APPFILEMANIFEST") 47 | appTitle <- optional("INPUT_APPTITLE") 48 | logLevel <- optional("INPUT_LOGLEVEL") 49 | 50 | # process appFiles 51 | if (!is.null(appFiles)) { 52 | appFiles <- unlist(strsplit(appFiles, ",", TRUE)) 53 | } 54 | 55 | # set up account 56 | cat("checking account info...") 57 | rsconnect::setAccountInfo(accountName, accountToken, accountSecret) 58 | cat(" [OK]\n") 59 | 60 | # deploy application 61 | rsconnect::deployApp( 62 | appDir = appDir, 63 | appFiles = appFiles, 64 | appFileManifest = appFileManifest, 65 | appName = appName, 66 | appTitle = appTitle, 67 | account = accountName 68 | ) --------------------------------------------------------------------------------