From ae6f261e0862887af14a3473152b528f9a5e0ab6 Mon Sep 17 00:00:00 2001 From: Chris <53177842+ChristopherMarais@users.noreply.github.com> Date: Sat, 24 Feb 2024 19:22:49 -0500 Subject: [PATCH] add files to be submitted to shinyapps.io --- 05_DASHBOARD/app.R | 2 +- 05_DASHBOARD/deploy-dev.R | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/05_DASHBOARD/app.R b/05_DASHBOARD/app.R index 424750b..8d71a29 100644 --- a/05_DASHBOARD/app.R +++ b/05_DASHBOARD/app.R @@ -39,7 +39,7 @@ find_directory_of_file <- function(file_name, start_dir=getwd()) { # find file_name from current working directory # before trying from a shallower directory -file_name <- "*05_DASHBOARD/app.R" # The file you are searching for +file_name <- "*DASHBOARD/app.R" # The file you are searching for try({ found_dir <- find_directory_of_file(file_name) diff --git a/05_DASHBOARD/deploy-dev.R b/05_DASHBOARD/deploy-dev.R index 88239a0..1b235b9 100644 --- a/05_DASHBOARD/deploy-dev.R +++ b/05_DASHBOARD/deploy-dev.R @@ -1,6 +1,27 @@ # Load the rsconnect package library(rsconnect) +# a function to list all files in a directory and its subdirectories +list_all_files <- function(directories) { + all_files <- c() # Initialize an empty vector to store all file paths + + # Loop through each directory provided + for (dir in directories) { + if (!dir.exists(dir)) { + next # Skip if directory does not exist + } + + # Use list.files to recursively list all files in the directory and its subdirectories + # full.names = TRUE returns the full paths, which is what we want + files <- list.files(dir, recursive = TRUE, full.names = TRUE) + + # Append the files found to the all_files vector + all_files <- c(all_files, files) + } + + return(all_files) +} + # Authenticate rsconnect::setAccountInfo( name = Sys.getenv("SHINY_ACC_NAME"), @@ -8,8 +29,9 @@ rsconnect::setAccountInfo( secret = Sys.getenv("SHINY_SECRET")) # Deploy +req_files <- list_all_files(c("./04_Tests", "./03_Data_for_app")) # get all the required files rsconnect::deployApp( appDir = "./05_DASHBOARD", - appFiles = "app.R", + appFiles = c("app.R", req_files), appName = "Dashboard-dev", forceUpdate = TRUE)