Skip to content

Commit

Permalink
Merge branch 'feature/10_feature' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherMarais committed Feb 25, 2024
2 parents fbd996d + daf79af commit 1d8ee85
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions 05_DASHBOARD/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
1 change: 1 addition & 0 deletions 05_DASHBOARD/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 0 additions & 2 deletions 05_DASHBOARD/deploy-dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ rsconnect::setAccountInfo(

# Deploy
rsconnect::deployApp(
appDir = "./05_DASHBOARD",
appFiles = "app.R",
appName = "Dashboard-dev",
forceUpdate = TRUE)
5 changes: 2 additions & 3 deletions 05_DASHBOARD/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ rsconnect::setAccountInfo(

# Deploy
rsconnect::deployApp(

appFiles = "app.R",
appName = "Dashboard")
appName = "Dashboard",
forceUpdate = TRUE)
54 changes: 50 additions & 4 deletions 05_DASHBOARD/app.R → app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 1d8ee85

Please sign in to comment.