-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.R
62 lines (51 loc) · 2.91 KB
/
global.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Global settings, e.g. reading in of packages, data
#### Install / load packages ---------------------------------
if(!require(shiny)){ install.packages("shiny") } ; library(shiny)
if(!require(shinydashboard)){ install.packages("shinydashboard") } ; library(shinydashboard)
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)
if(!require(plotly)){ install.packages("plotly") } ; library(plotly)
#### Get app.R file dir and set work dir ---------------------
# 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
### Load shapefiles ------------------------------------------------
##### GTMNERR shapefile ------------------------------------------------
GTMNERR <- st_read("./03_Data_for_app/shapefiles_new/GTMNERR_small_nosea.shp")
##### county shapefiles ------------------------------------------------
counties_select <- st_read("./03_Data_for_app/shapefiles_new/counties_GTMNERR.shp")
##### HUC shapefiles ------------------------------------------------
HUC10 <- st_read("./03_Data_for_app/shapefiles_new/nhdwbd_huc10_dec17_GTMNERR.shp")
HUC12 <- st_read("./03_Data_for_app/shapefiles_new/nhdwbd_huc12_dec17_GTMNERR.shp")
##### Outstanding Florida Waters (OFW) shapefiles ------------------------------
ofw <- st_read("./03_Data_for_app/shapefiles_new/ofw_GTMNERR.shp")
##### mangrove shapefiles -----------------------------------------------------
mangroves <- st_read("./03_Data_for_app/shapefiles_new/mangrove_GTMNERR.shp")
##### salt marsh shapefiles -----------------------------------------------------
saltmarsh <- st_read("./03_Data_for_app/shapefiles_new/salt_marsh_GTMNERR.shp")