diff --git a/04_Tests/HAB_test/app.R b/04_Tests/HAB_test/HAB_test_app.R old mode 100755 new mode 100644 similarity index 100% rename from 04_Tests/HAB_test/app.R rename to 04_Tests/HAB_test/HAB_test_app.R diff --git a/04_Tests/leaflet_test1/app.R b/04_Tests/leaflet_test1/leaflet_test_app.R similarity index 100% rename from 04_Tests/leaflet_test1/app.R rename to 04_Tests/leaflet_test1/leaflet_test_app.R diff --git a/05_DASHBOARD/Dockerfile b/05_DASHBOARD/Dockerfile index e9769d1..df362d8 100644 --- a/05_DASHBOARD/Dockerfile +++ b/05_DASHBOARD/Dockerfile @@ -6,6 +6,7 @@ ENV BRANCH_NAME=${BRANCH_NAME} RUN install2.r rsconnect shiny tidyverse bslib leaflet sf WORKDIR /usr/src/dashboard-development # Copy the 'app' directory contents into the container +COPY ./app.R /usr/src/dashboard-development/ COPY ./03_Data_for_app /usr/src/dashboard-development/03_Data_for_app/ COPY ./04_Tests /usr/src/dashboard-development/04_Tests/ COPY ./05_DASHBOARD /usr/src/dashboard-development/05_DASHBOARD/ diff --git a/05_DASHBOARD/Dockerfile-dev b/05_DASHBOARD/Dockerfile-dev index 1a6f996..e10745d 100644 --- a/05_DASHBOARD/Dockerfile-dev +++ b/05_DASHBOARD/Dockerfile-dev @@ -6,6 +6,7 @@ ENV BRANCH_NAME=${BRANCH_NAME} RUN install2.r rsconnect shiny tidyverse bslib leaflet sf WORKDIR /usr/src/dashboard-development # Copy the 'app' directory contents into the container +COPY ./app.R /usr/src/dashboard-development/ COPY ./03_Data_for_app /usr/src/dashboard-development/03_Data_for_app/ COPY ./04_Tests /usr/src/dashboard-development/04_Tests/ COPY ./05_DASHBOARD /usr/src/dashboard-development/05_DASHBOARD/ diff --git a/05_DASHBOARD/deploy-dev.R b/05_DASHBOARD/deploy-dev.R index 88239a0..42cdb42 100644 --- a/05_DASHBOARD/deploy-dev.R +++ b/05_DASHBOARD/deploy-dev.R @@ -9,7 +9,5 @@ rsconnect::setAccountInfo( # Deploy rsconnect::deployApp( - appDir = "./05_DASHBOARD", - appFiles = "app.R", appName = "Dashboard-dev", forceUpdate = TRUE) diff --git a/05_DASHBOARD/deploy.R b/05_DASHBOARD/deploy.R index 580835f..3543d46 100644 --- a/05_DASHBOARD/deploy.R +++ b/05_DASHBOARD/deploy.R @@ -9,6 +9,5 @@ rsconnect::setAccountInfo( # Deploy rsconnect::deployApp( - - appFiles = "app.R", - appName = "Dashboard") + appName = "Dashboard", + forceUpdate = TRUE) diff --git a/05_DASHBOARD/app.R b/app.R similarity index 75% rename from 05_DASHBOARD/app.R rename to app.R index a8c190a..028b0ed 100644 --- a/05_DASHBOARD/app.R +++ b/app.R @@ -12,27 +12,73 @@ if(!require(tidyverse)){ install.packages("tidyverse") } ; library(tidyverse) if(!require(bslib)){ install.packages("bslib") } ; library(bslib) if(!require(leaflet)){ install.packages("leaflet") } ; library(leaflet) if(!require(sf)){ install.packages("sf") } ; library(sf) +if(!require(fs)){ install.packages("fs") } ; library(fs) ### READ IN DATA --------------------------------------------- # For some reason I need to specify my whole path to the data here (even though # I am working in an Rproject) # NOTE: .RData restores the object to the name it had when you saved it as .RData -#load("03_Data_for_app/HAB.RData") +#load("03_Data_for_app/HAB.RData") + +#### Get app.R file dir and set work dir --------------------- +# Function to find the directory of a file named app.R +find_directory_of_file <- function(file_name, start_dir=getwd()) { + # Recursively list all files starting from the start_dir + app_dir <- fs::dir_ls(start_dir, recurse = TRUE, glob=file_name) + + # Check if any file named app.R is found + if (length(app_dir) > 0) { + # Assuming you want the directory of the first matching file + file_dir <- fs::path_dir(app_dir[1]) + return(file_dir) + } else { + return(NULL) # Return NULL if the file is not found + } +} + +# find file_name from current working directory +# before trying from a shallower directory +file_name <- "*/app.R" # The file you are searching for + +try({ + found_dir <- find_directory_of_file(file_name) + # Check if found_dir is NULL or empty, indicating the file was not found + if (is.null(found_dir) || length(found_dir) == 0) { + # print error + print("/app.R not found from current working directory!") + print("trying again from shallower directory") + # trying again from great grandparent directory of working directory + setwd("../../..") + found_dir <- find_directory_of_file(file_name) + if (is.null(found_dir) || length(found_dir) == 0) { + print("app.R likely does not exist in filesystem!") + } + # Set working directory to parent directory of found dir + setwd(fs::path_dir(found_dir[1])) + # Print working directory + print(paste0("Working dir: ", getwd())) + } + # Set working directory to parent directory of found dir + setwd(found_dir[1]) + # Print working directory + print(paste0("Working dir: ", getwd())) +}, silent = FALSE) # Setting silent = FALSE will print the error message to the console + #### HAB data ------------------------------------------------ -load("~/github/GTMNERR Science Transfer/App_dev/03_Data_for_app/HAB.RData") +load("./03_Data_for_app/HAB.RData") HAB_data_locations <- HAB %>% select(Latitude, Longitude, Site, `Collection Agency`, County) %>% # took out `HAB ID` (otherwise 1172 instead of 17 locations) distinct() %>% st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) #### GTMNERR shapefile ------------------------------------------------ -GTMNERR <- st_read("~/github/GTMNERR Science Transfer/App_dev/03_Data_for_app/shapefiles_new/GTMNERR.shp") +GTMNERR <- st_read("./03_Data_for_app/shapefiles_new/GTMNERR.shp") GTMNERR <- st_transform(GTMNERR, crs = 4326) #### county shapefiles ------------------------------------------------ -counties_select <- st_read("~/github/GTMNERR Science Transfer/App_dev/03_Data_for_app/shapefiles_new/counties_GTMNERR.shp") +counties_select <- st_read("./03_Data_for_app/shapefiles_new/counties_GTMNERR.shp") counties_select <- st_transform(counties_select, crs = 4326)