-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeat_consumption.R
More file actions
251 lines (221 loc) · 8.88 KB
/
meat_consumption.R
File metadata and controls
251 lines (221 loc) · 8.88 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
library(shiny)
library(plotly)
library(dplyr)
library(tidyr)
animals_slaughtered_for_meat <- read.csv("animals-slaughtered-for-meat.csv")
colnames(animals_slaughtered_for_meat) <- c("Entity","Code", "Year", "Cattle", "Goats", "Chicken", "Turkey", "Pigs", "Sheep")
animals_slaughtered_for_meat <- animals_slaughtered_for_meat[!is.na(animals_slaughtered_for_meat$Code),]
meat<-read.csv('per-capita-meat-consumption-by-type-kilograms-per-year.csv',sep = ',' )
colnames(meat)<-c("Entity","Code","Year","Mutton & Goat","Other meat","Poultry","Pigmeat","Cattle")
meat <- meat[!is.na(meat$Code),]
ui<-fluidPage(
fluidRow(
column(12,
"Meat consumption in the world",
fluidRow(
column(6,
plotlyOutput("glob"),
fluidRow(
column(6,
selectInput("gatunek",
"Species:",
choices = c("Cattle","Goats", "Chicken", "Turkey","Pigs", "Sheep" ),
selected = "Cattle") ),
column(6,
sliderInput("zakres",
"Year:",
value = min(animals_slaughtered_for_meat$Year),
min = min(animals_slaughtered_for_meat$Year),
max = max(animals_slaughtered_for_meat$Year),
step = 1,
animate = animationOptions(interval = 500)))
),
h4("Map above represents number of slaughtered animals of chosen species by country in the chosen year ")
),
column(6,
plotlyOutput("glob1"),
fluidRow(
column(6,
selectInput("typ",
"Species:",
choices = c("Mutton & Goat", "Other meat" ,"Poultry","Pigs","Cattle"),
selected = "Cattle")),
column(6,
sliderInput("zakres1",
"Year:",
value = min(meat$Year),
min = min(meat$Year),
max = max(meat$Year),
step = 1,
animate = animationOptions(interval = 500)))
)
),
h4("Map above represents consumption per capita of chosen species by country in the chosen year")
)
)
),
h2(" "),
textOutput("text"),
sliderInput("przed",
"Time period:",
value = c(min(meat$Year), max(meat$Year)),
min = min(meat$Year),
max = max(meat$Year),
step = 1),
DT::dataTableOutput("mytable"),
h4("Table represents summary of the consumption of in the chosen country in the chosen time period")
)
server <- function(input, output) {
output$glob1 <- renderPlotly({
meat1<-meat %>%
filter(Year == input$zakres1)
if (input$typ == "Mutton & Goat"){
plot_ly(data = meat1,
type = 'choropleth',
locations = ~Code,
z = meat1$`Mutton & Goat`,
zmin = 0,
zmax = 61.34,
text = ~Entity,
colorscale = "Reds") %>%
layout(title = "Mutton and goat meat consumption per capita per country in kgs",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$typ == "Other meat"){
plot_ly(data = meat1,
type = 'choropleth',
locations = ~Code,
z = meat1$`Other meat`,
zmin = 0,
zmax = 65.18,
text = ~Entity,
colorscale = "Reds") %>%
layout(title = "Other meat consumption per capita per country in kgs",
geo = list(projection = list(type = 'natural earth')))
}else if (input$typ == "Poultry"){
plot_ly(data = meat1,
type = 'choropleth',
locations = ~Code,
z = meat1$Poultry,
zmin = 0,
zmax = 87.82,
text = ~Entity,
colorscale = "Reds") %>%
layout(title = "Poultry consumption per capita per country in kg",
geo = list(projection = list(type = 'natural earth')))
}else if (input$typ == "Pigmeat"){
plot_ly(data = meat1,
type = 'choropleth',
locations = ~Code,
z = meat1$Pigmeat,
zmin = 0,
zmax = 77.93,
text = ~Entity,
colorscale = "Reds") %>%
layout(title = "Pigmeat consumption per capita per country in kg",
geo = list(projection = list(type = 'natural earth')))
}else {
plot_ly(data = meat1,
type = 'choropleth',
locations = ~Code,
z = meat1$Cattle,
zmin = 0,
zmax = 93.25,
text = ~Entity,
colorscale = "Reds") %>%
layout(title = "Cattle consumption per capita per country in kg",
geo = list(projection = list(type = 'natural earth')))}
})
output$glob <- renderPlotly({
df <- animals_slaughtered_for_meat %>%
filter(Year == input$zakres)
if (input$gatunek == "Cattle"){
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Cattle,
zmin = 0,
zmax = 48726000,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of cattle slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$gatunek == "Goats") {
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Goats,
zmin = 0,
zmax = 162761966,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of goats slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$gatunek == "Chicken") {
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Chicken,
zmin = 0,
zmax = 10510737000,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of chickens slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$gatunek == "Turkey") {
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Turkey,
zmin = 0,
zmax = 293290000,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of turkeys slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$gatunek == "Pigs") {
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Pigs,
zmin = 744899496,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of pigs slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
else if (input$gatunek == "Sheep") {
plot_ly(data = df,
type = 'choropleth',
locations = ~Code,
z = ~Sheep,
zmin = 0,
zmax = 144265012,
text = ~Entity,
colors = "Reds") %>%
layout(title = "Number of sheep slaughtered per country",
geo = list(projection = list(type = 'natural earth')))
}
})
output$text <- renderText(({
paste("Sum of all meat consumed by country in years ", input$przed[1], "-", input$przed[2])
}))
output$mytable = DT::renderDataTable({
jak <- meat
jak$Suma <-rowSums(jak[, c(4:8)], na.rm = TRUE)
g <- jak %>%
select(Entity, Year, Suma) %>%
filter(Year >= input$przed[1],
Year <= input$przed[2]) %>%
group_by(Entity) %>%
summarise(Sum_avg = round(mean(Suma)),
Sum_min = min(Suma),
Sum_max = max(Suma))
g
})
}
shinyApp(ui = ui, server = server)