-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
128 lines (110 loc) · 4.21 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
### File: global.R
###
### Template Created: 14/07/2020 08:55:00
### Author: Guillermo Martin
###
####################################################################################################
### Description:
###
### Global functions to load packages and Inshore database data
###
###
# Used packages
packs = c("shiny",
"shinyBS",
"shinydashboard",
"shinythemes",
"shinyjs",
"shinyWidgets",
"leaflet",
"dplyr",
"tidyr",
"ggplot2",
"lubridate",
"plotly",
"sp",
"sf",
#"rgdal",
"shinycssloaders",
"ggsci",
"ggthemes",
"paletteer",
#"colorRamps",
"ggrepel",
"rintrojs",
"fontawesome")
# Run the following command to verify that the required packages are installed. If some package
# is missing, it will be installed automatically
package.check <- lapply(packs, FUN = function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
}
})
library(shiny)
# Intro steps
intro<-read.csv("./data/intro.csv")
##Loading Inshore fisheries data:
catch_plot<-read.csv("./data/Data_prep_Output/catch_plot.csv")
#Biological data
bio<-read.csv("data/Data_prep_Output/bio_summary.csv")
#Summary statistics
dat_sta<-read.csv("data/Data_prep_Output/Programme_summary.csv")
minY<-as.numeric(min(dat_sta$Year))
maxY<-as.numeric(max(dat_sta$Year))
#Landings table
landings<-read.csv(file.path("data/Data_prep_Output/",
"Landings_Table.csv"))
landings <- landings %>%
pivot_longer(cols = starts_with("X"),
names_to = "Year",
values_to = "Landings") %>%
mutate(Year=gsub("x","",Year,ignore.case = T)) %>%
filter(Year <= maxY) %>%
data.frame()
#Adding Scientific Name
landings$ScientificName<-NA
landings$ScientificName[landings$SpeciesName == "Cockle"]<-"(Cerastoderma edule)"
landings$ScientificName[landings$SpeciesName == "Crayfish"]<-"(Palinurus elephas)"
landings$ScientificName[landings$SpeciesName == "Edible crab"]<-"(Cancer pagurus)"
landings$ScientificName[landings$SpeciesName == "King Scallop"]<-"(Pecten maximus)"
landings$ScientificName[landings$SpeciesName == "Lobster"]<-"(Homarus gammarus)"
landings$ScientificName[landings$SpeciesName == "Native oyster"]<-"(Ostrea edulis)"
landings$ScientificName[landings$SpeciesName == "Queen scallop"]<-"(Aequipecten opercularis)"
landings$ScientificName[landings$SpeciesName == "Razor clams"]<-"(Ensis sp.)"
landings$ScientificName[landings$SpeciesName == "Shore crab"]<-"(Carcinus sp.)"
landings$ScientificName[landings$SpeciesName == "Shrimp"]<-"(Palaemon sp./Crangon sp.)"
landings$ScientificName[landings$SpeciesName == "Spider crab"]<-"(Maja squinado)"
landings$ScientificName[landings$SpeciesName == "Surf clam"]<-"(Spisula sp.)"
landings$ScientificName[landings$SpeciesName == "Velvet crab"]<-"(Necora puber)"
landings$ScientificName[landings$SpeciesName == "Whelk"]<-"(Buccinum undatum)"
landings$SS<-paste(landings$SpeciesName,landings$ScientificName,sep=" ")
#Assessment and advice table
# Bivalves:
ba_a<-read.csv("data/Data_prep_Output/Bivalves Assessment and Advice.csv")
ba_a<-ba_a[order(ba_a$Specie,ba_a$Area,-ba_a$Year),]
#Crustaceans:
ca_a<-read.csv("data/Data_prep_Output/Crustacean Assessment and Advice.csv")
#Loading Spatial Data
source("./lib/01_Loading_Spatial_Data.R",
encoding="latin1")
#Additional functions and Shinny formatting
source("./lib/help_funs.R",
encoding="latin1")
source("./lib/override.R",
local = TRUE)
#Load data at ICES_rectangle
ICES_LPUE<-st_read(dsn = "data/Data_prep_Output",
layer = "ICES_LPUE")
#encoding = "utf8")
#ICES_LPUE <- spTransform(ICES_LPUE, CRSobj=projWGS84)
ICES_LPUE <- st_transform(ICES_LPUE, CRSobj=projWGS84)
#ICES_LPUE<-st_as_sf(ICES_LPUE)
#Read rds file related to the polygons
ICES_dat<-readRDS(file=file.path("data/Data_prep_Output/ICES_slope_data.rds"))
ICES_dat<-subset(ICES_dat,Year <= maxY)
ICES_dat <- ICES_dat %>%
group_by(Year) %>%
arrange(EventStartDate) %>%
ungroup() %>%
mutate(units=ifelse(CommonName %in% "EDIBLE CRAB UNSEXED","kg/Pot","Number/100 Pots")) %>%
data.frame()