deploy.R

library(rsconnect)
# Check secrets function:----
#' Check secrets
#' a function to stop the script when one of the variables cannot be found.
#' and to strip quotation marks from the secrets when you supplied them.
#' (maybe it is just easier to never use them)
#'
#' @param name The name of the secret/variable to find
#'
#' @return Unquoted value of the secret
#' @export
#'
#' @examples
error_on_missing_name <- function(name) {
  var <- Sys.getenv(name, unset = NA)

  if(is.na(var)) {
    stop(paste0("cannot find ", name, " !"), call. = FALSE)
  }
  gsub("\"", '', var)

}

# Authenticate:----
rsconnect::setAccountInfo(
  name = error_on_missing_name("SHINY_ACC_NAME"),
  token = error_on_missing_name("TOKEN"),
  secret = error_on_missing_name("SECRET")
)

# Deploy the application:----
rsconnect::deployApp(
  appDir = file.path(
    here::here(),
    "inst",
    "shiny-examples",
    "ShinyPSA"
  ),
  appFiles = NULL,
  #c("app.R" #, you can specify which files to deploy,
  #or keep this NULL to deploy everything)

  appName = error_on_missing_name("MASTERNAME"),
  appTitle = "ShinyPSA",
  forceUpdate = TRUE
)
W-Mohammed/ShinyPSA documentation built on April 24, 2022, 6:57 p.m.