forked from OHI-Science/global-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
155 lines (124 loc) · 5.7 KB
/
server.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function(input, output, session) {
## Finfish Aquaculture Summary Stats ##
callModule(summary_stats, "fish_metrics",
number_boxes = 3,
statistic = list("51%", "$203 M", "35%"),
text = list("of sales in USD are from catfish, followed by trout at 15%, and bass at 7%.",
"in finfish aquaculture products were sold in Mississippi, the highest food fish producing state.",
"of food fish farms were located in Mississippi, Alabama, and North Carolina."))
## Food Fish Aquaculture Map ##
callModule(card_choro_map, "fish_us_map",
data = fish_us_map,
field = "input",
filter_field = type, # type of data to plot
popup_value = "map_data",
popup_units = "units",
color_palette = ygb[80:200],
color_palette_type = "quantile",
legend_title = "Legend",
popup_label = "state")
## Food Fish Sales/Operation Timeseries ##
callModule(card_plot, "fish_dolop_plot",
fish_dolop_plot,
x = "OPERATIONS",
y = "DOLLARS",
plot_type = "scatter",
filter_field = "Year", # filter for slider input
color_group = "Quantile",
colors = ygb_cols,
legendText = "Sales per Operation",
# annotations = list(
# text="Sales per Operation", # manually placed legend
# xref="paper", yref="paper",
# x=1.02, xanchor="left",
# y=0.8, yanchor="bottom", # Same y as legend below
# legendtitle=TRUE,
# showarrow=FALSE
# ),
mode = "text",
tooltip_text = ~State,
textposition = 'middle right', # "middle right", "top center"
xaxis_label = "No. of Farms",
yaxis_label = "Sales in US Dollars",
xaxis_range = c(0,220),
x_dtick = 50, # distance between ticks
x_tickangle = 360, # normal angle
yaxis_range = c(0,120000000))
# Problem is that Mississippi is a huge outlier
## Mollusk Aquaculture Summary Stats ##
callModule(summary_stats, "shell_metrics",
number_boxes = 3,
statistic = list("55%", "45%", "52%"),
text = list("of US mollusk sales are oysters, 38% are clams and 4% are mussels.",
"of mollusk aquaculture sales were produced in Washington during 2013.",
"of mollusk farms are in Florida, Massachusetts, and Washington."))
## Mollusk Aquaculture Map ##
callModule(card_choro_map, "shell_us_map",
data = shell_us_map,
field = "input",
filter_field = type, # type of data to plot
popup_value = "map_data",
popup_units = "units",
color_palette = ygb[80:200],
color_palette_type = "quantile",
legend_title = "Legend",
popup_label = "state")
## Mollusk Sales/Operation Timeseries ##
callModule(card_plot, "moll_dolop_plot",
fish_dolop_plot,
x = "OPERATIONS",
y = "DOLLARS",
plot_type = "scatter",
filter_field = "Year", # filter for slider input
mode = "text",
tooltip_text = ~State,
textposition = 'middle right', # "middle right", "top center"
xaxis_label = "No. of Farms",
yaxis_label = "Sales in US Dollars",
xaxis_range = c(0,225),
x_dtick = 50, # distance between ticks
x_tickangle = 360, # normal angle
yaxis_range = c(0,150000000))
## FDA Shrimp Import Refusal Summary Stats ##
callModule(summary_stats, "shrimp_metrics",
number_boxes = 3,
statistic = list("40%", "15%", "36%"),
text = list("of shrimp import refusals over the last 10 years came from India and Malaysia equally, the top two offending countries.",
"of shrimp import refusals over the last 10 years came from Vietnam, followed by Indonesia at 10%.",
"of refusals in recent years were due to presence of Salmonella. Traces of veterinary drugs came in second at 19%."))
## FDA Shrimp Import Refusal Counts Map ##
callModule(card_dot_map, "shrimp_dot_map",
data = shrimp_refuse_dot,
field = "input",
filter_field = YEAR, # slider data filter
col = OrRd[150],
lon_field = "LON",
lat_field = "LAT",
popup_label = "COUNTRY_NAME",
popup_value = "REFUSAL_NUM",
popup_units = "Refusals",
label_font_size = "12px",
chart_width = "REFUSAL_NUM",
lon = 12,
lat = 30,
zoom = 2)
## FDA Shrimp Import Refusal Charges Stacked Plot ##
callModule(card_plot, "shrimp_stacked_plot",
shrimp_stacked,
x = "YEAR",
y = "REFUSAL_COUNT",
xaxis_range = c(2001.5,2018.5),
yaxis_range = c(0,max(shrimp_stacked$REFUSAL_COUNT)),
color_group = "DESCRIPTION",
filter_field = "COUNTRY_NAME",
colors = ygb_cols,
mode = NULL,
plot_type = "bar",
barmode = "stack",
tooltip_text = ~paste("Charge: ", map(DESCRIPTION, capStr),
"<br>Refused:", REFUSAL_COUNT, "Imports", sep=" "),
xaxis_label = "Year",
yaxis_label = "Refusal Charge Count",
x_tickangle = 45,
x_dtick = 1)
}