Skip to content

Instantly share code, notes, and snippets.

@dancingfrog
Created December 20, 2022 14:39
Show Gist options
  • Save dancingfrog/58c7bc33b44e33704753fb7e23487747 to your computer and use it in GitHub Desktop.
Save dancingfrog/58c7bc33b44e33704753fb7e23487747 to your computer and use it in GitHub Desktop.
.deploy-shiny-app.R
if (!require(rsconnect)) {
install.packages("rsconnect")
library("rsconnect")
}
options(rsconnect.max.bundle.size = 9145728000)
# Print a list of app dependencies. Libraries need to be loaded
# before publishing so deployApp() knows what is necessary.
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)
}
account_name <- error_on_missing_name("SHINY_ACC_NAME")
app_server <- "shinyapps.io"
app_name <- error_on_missing_name("NAME")
app_title <- ifelse(Sys.getenv("TITLE") != "", Sys.getenv("TITLE"), "shinyapplication")
print(paste0("Deploying ", app_name, " to ", account_name, ".", app_server))
if (dir.exists("renv")) {
renv::restore(prompt = FALSE)
} else if (dir.exists("packrat")) try({
print("Packrat config detected!")
source("packrat/init.R")
packrat::restore(overwrite.dirty = TRUE)
})
# Set the account info for deployment.
rsconnect::setAccountInfo(name = account_name, token = error_on_missing_name("TOKEN"), secret = error_on_missing_name("SECRET"))
print("Ready to deploy from local app directory:")
print(list.files(all.files = TRUE, include.dirs = TRUE))
rsconnect::deployApp(
appDir = getwd(),
account = account_name,
server = app_server,
appName = app_name,
appTitle = app_title,
launch.browser = function(url) {
message("Deployment completed: ", url)
},
lint = FALSE,
metadata = list(asMultiple = FALSE, asStatic = FALSE, ignoredFiles = "Dockerfile|.deploy-shiny-app.R|.exec-shiny-app.R|package.csv|.RData|README.md|.Renviron|.Rprofile|shiny_data_prep.R|shiny_test.R|test.R"),
logLevel = "verbose"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment