-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
2121 lines (1835 loc) · 143 KB
/
app.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# JMMI Dashboard
# 08.06.21
# With food components
#GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL GLOBAL
# setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
#install packages
library(devtools)
library(usethis)
library(shiny)
library(shinyjs)
library(rgdal)
library(dplyr)
library(leaflet)
library(highcharter)
library(zoo)
library(ggplot2)
library(rgeos)
library(classInt)
library(geosphere)
library(shinythemes)
library(sf)
library(purrr)
library(shinydashboard)
library(readxl)
library(DT)
library(formattable)
library(tibble)
library(curl)
library(sp)
library(stringr)
library(shinyWidgets)
library(leaflet.extras)
library(kableExtra)
library(tidytidbits)
library(data.table)
library(openxlsx)
library(grDevices)
library(sass)
library(scales)
library(htmltools)
library(httr)
set_config(use_proxy(url="10.3.100.207",port=8080)) # to solve "error in curl::curl_fetch_memory
addLegend_decreasing <- function (map, position = c("topright", "bottomright", "bottomleft",
"topleft"), pal, values, na.label = "NA", bins = 7, colors,
opacity = 0.5, labels = NULL, labFormat = labelFormat(),
title = NULL, className = "info legend", layerId = NULL,
group = NULL, data = getMapData(map), decreasing = FALSE) {
position <- match.arg(position)
type <- "unknown"
na.color <- NULL
extra <- NULL
if (!missing(pal)) {
if (!missing(colors))
stop("You must provide either 'pal' or 'colors' (not both)")
if (missing(title) && inherits(values, "formula"))
title <- deparse(values[[2]])
values <- evalFormula(values, data)
type <- attr(pal, "colorType", exact = TRUE)
args <- attr(pal, "colorArgs", exact = TRUE)
na.color <- args$na.color
if (!is.null(na.color) && col2rgb(na.color, alpha = TRUE)[[4]] ==
0) {
na.color <- NULL
}
if (type != "numeric" && !missing(bins))
warning("'bins' is ignored because the palette type is not numeric")
if (type == "numeric") {
cuts <- if (length(bins) == 1)
pretty(values, bins)
else bins
if (length(bins) > 2)
if (!all(abs(diff(bins, differences = 2)) <=
sqrt(.Machine$double.eps)))
stop("The vector of breaks 'bins' must be equally spaced")
n <- length(cuts)
r <- range(values, na.rm = TRUE)
cuts <- cuts[cuts >= r[1] & cuts <= r[2]]
n <- length(cuts)
p <- (cuts - r[1])/(r[2] - r[1])
extra <- list(p_1 = p[1], p_n = p[n])
p <- c("", paste0(100 * p, "%"), "")
if (decreasing == TRUE){
colors <- pal(rev(c(r[1], cuts, r[2])))
labels <- rev(labFormat(type = "numeric", cuts))
}else{
colors <- pal(c(r[1], cuts, r[2]))
labels <- rev(labFormat(type = "numeric", cuts))
}
colors <- paste(colors, p, sep = " ", collapse = ", ")
}
else if (type == "bin") {
cuts <- args$bins
n <- length(cuts)
mids <- (cuts[-1] + cuts[-n])/2
if (decreasing == TRUE){
colors <- pal(rev(mids))
labels <- rev(labFormat(type = "bin", cuts))
}else{
colors <- pal(mids)
labels <- labFormat(type = "bin", cuts)
}
}
else if (type == "quantile") {
p <- args$probs
n <- length(p)
cuts <- quantile(values, probs = p, na.rm = TRUE)
mids <- quantile(values, probs = (p[-1] + p[-n])/2,
na.rm = TRUE)
if (decreasing == TRUE){
colors <- pal(rev(mids))
labels <- rev(labFormat(type = "quantile", cuts, p))
}else{
colors <- pal(mids)
labels <- labFormat(type = "quantile", cuts, p)
}
}
else if (type == "factor") {
v <- sort(unique(na.omit(values)))
colors <- pal(v)
labels <- labFormat(type = "factor", v)
if (decreasing == TRUE){
colors <- pal(rev(v))
labels <- rev(labFormat(type = "factor", v))
}else{
colors <- pal(v)
labels <- labFormat(type = "factor", v)
}
}
else stop("Palette function not supported")
if (!any(is.na(values)))
na.color <- NULL
}
else {
if (length(colors) != length(labels))
stop("'colors' and 'labels' must be of the same length")
}
legend <- list(colors = I(unname(colors)), labels = I(unname(labels)),
na_color = na.color, na_label = na.label, opacity = opacity,
position = position, type = type, title = title, extra = extra,
layerId = layerId, className = className, group = group)
invokeMethod(map, data, "addLegend", legend)
}
round_df <- function(df, digits) {
nums <- vapply(df, is.numeric, FUN.VALUE = logical(1))
df[,nums] <- round(df[,nums], digits = digits)
(df)
}
##-------------------------- TABULAR DATA WRANGLE ----------------------
# Full database for data explorer at KII level
full_data <- read.csv("data/data_all.csv", stringsAsFactors = F) %>%
dplyr::select(-matches("district_au|cash_feasibility|market_|_source|exchange_rate_market\\.|type_market|_other|infra|^X$"), -ends_with("mrk_supply_issues"), -ends_with("other"), -ends_with("not_answer")) %>%
dplyr::rename(Date=date, Governorate=government_name, District=district_name) %>%
dplyr::mutate(Date=as.Date(as.yearmon(Date)))
## import names label for full dataset
indicator_list_full <- read.xlsx("indicator_list.xlsx", sheet = 2)
# Full database for data explorer at district level + Plot tab
indicators <- read.csv("data/data_market_functionnality.csv", stringsAsFactors = F) %>%
dplyr::select(-matches("X|country|district_au|cash_feasibility|market_|_source|exchange_rate_|type_market|_other|infra"), -ends_with("mrk_supply_issues"), -ends_with("other"), -ends_with("not_answer")) %>%
dplyr::select(jmmi_date, governorate_name, district_name, 7:ncol(.)) %>%
tidyr::gather(Indicator, Value, 4:(ncol(.))) %>%
dplyr::rename(date=jmmi_date, governorate=governorate_name, district=district_name) %>%
dplyr::group_by(date, governorate, district, Indicator) %>%
dplyr::summarise(freq = sum(Value == 1 | Value == "yes" | Value == "Yes", na.rm = TRUE) / sum(!is.na(Value)) * 100) %>%
mutate_if(is.numeric, round, 0) %>% mutate(freq=ifelse(is.nan(freq), NA, freq)) %>%
tidyr::spread(Indicator, freq) %>%
dplyr::rename(Date = date, Governorate = governorate, District = district) %>% ungroup
indicators_long <- indicators %>%
tidyr::pivot_longer(cols = 4:ncol(.)) %>%
dplyr::rename(Item=name, Price=value)
# Summarizing market functionnality indicators at gov and national level
indicators_admin1 <- indicators %>% dplyr::select(-District) %>% group_by(Date, Governorate) %>%
summarise_at(vars(-group_cols()), ~mean(., na.rm=T)) %>% mutate_at(vars(-group_cols()), ~ifelse(is.nan(.), NA, .))
indicators_admin0 <- indicators %>% dplyr::select(-District, -Governorate) %>% group_by(Date) %>%
summarise_at(vars(-group_cols()), ~mean(., na.rm=T))%>% mutate_at(vars(-group_cols()), ~ifelse(is.nan(.), NA, .))
## Uploading national, governorate and district data
AdminNatData <- read.csv("data/national_interactive.csv", stringsAsFactors = F) %>% as_tibble() %>% dplyr::select(-X) %>%
left_join(indicators_admin0, by=c("date"="Date"))
Admin1data <- read.csv("data/governorate_interactive.csv", stringsAsFactors = F) %>% as_tibble() %>% dplyr::select(-X) %>%
left_join(indicators_admin1, by=c("date"="Date", "government_name"="Governorate"))
Admin2data <- read.csv("data/district_interactive.csv", stringsAsFactors = F) %>% as_tibble()%>% dplyr::select(-X) %>%
left_join(indicators, by = c("date"="Date", "government_name"="Governorate", "district_name"="District"))
## SMEB Calculation - update the SMEB in this function only!
food.smeb.items <- c("wheat_flour","beans_dry","vegetable_oil","sugar","salt")
wash.smeb.items <- c("soap","laundry_powder","sanitary_napkins","cost_cubic_meter")
smeb.items <- c(food.smeb.items, wash.smeb.items)
calculate.smeb <- function(df){
df <- df %>%
mutate(WASH_SMEB = (soap*10.5+laundry_powder*20+sanitary_napkins*5+as.numeric(cost_cubic_meter)*3.15) %>% as.numeric %>% round(.,0),
Food_SMEB = (wheat_flour*75+beans_dry*10+vegetable_oil*8+sugar*2.5+salt) %>% as.numeric %>% round(.,0),
NFI_Shelter_lumpsum = ifelse(aor == "North", 25000, ifelse(aor == "South", 28750, mean(c(25000,28750)))) %>% round(.,0),
Services_lumpsum = ifelse(aor == "North", 19000, ifelse(aor == "South", 21850, mean(c(19000,21850)))) %>% round(.,0),
SMEB = ifelse(!is.na(WASH_SMEB) & !is.na(Food_SMEB), WASH_SMEB + Food_SMEB + NFI_Shelter_lumpsum + Services_lumpsum %>% round(.,0), NA))
return(df)
}
## Calculate SMEB at district level
Admin2data <- Admin2data %>% calculate.smeb
## Aggregate SMEB and join to admin1 and national level
smeb_gov <- Admin2data %>% group_by(date, government_ID) %>% summarise_at(vars(matches("SMEB|lumpsum")), ~median(., na.rm=T))
Admin1data <- Admin1data %>% full_join(., smeb_gov, by = c("date", "government_ID"))
smeb_nat <- Admin2data %>% group_by(date) %>% summarise_at(vars(matches("SMEB|lumpsum")), ~median(., na.rm=T))
AdminNatData <- AdminNatData %>% full_join(., smeb_nat, by = c("date"))
max_date <- max(as.Date(as.yearmon(AdminNatData$date)))
# Wrangle Data into appropriate formats
# Governorates
Admin1table <- Admin1data %>% mutate_at(vars(-matches("date|aor|government")), ~ round(as.numeric(.)), 0) %>%
mutate(date2 = as.Date(as.yearmon(date)))
Admin1data_current <- Admin1table %>% arrange(desc(date2)) %>% dplyr::filter(date2 == max_date) # subset only recent month dates to attach to shapefile
currentD <- as.character(format(max(Admin1table$date2),"%B %Y")) # define current date for disply in dashboard
# Districts
Admin2table_p <- Admin2data %>% mutate_at(vars(-matches("date|aor|government|district")), ~ round(as.numeric(.)), 0) %>%
dplyr::mutate(date2 = as.Date(as.yearmon(date)), .before=1)
col.exclude <- c("jmmi|Date|aor|Governorate|government_ID|District|district_ID") # coverage
admin2coverage <- full_data %>% group_by(Date, district_ID) %>% summarise_at(vars(-matches(col.exclude)), ~ sum(!is.na(.))) %>% rename_at(vars(-matches(col.exclude)), ~paste0("n_",.)) %>%
rowwise() %>%
dplyr::mutate(n_SMEB = ifelse(min(c_across(paste0("n_", smeb.items)))>0, mean(c_across(paste0("n_", smeb.items))) %>% round(1), 0),
n_WASH_SMEB = ifelse(min(c_across(paste0("n_", wash.smeb.items)))>0, mean(c_across(paste0("n_", wash.smeb.items))) %>% round(1), 0),
n_Food_SMEB = ifelse(min(c_across(paste0("n_", food.smeb.items)))>0, mean(c_across(paste0("n_", food.smeb.items))) %>% round(1), 0))
Admin2table <- Admin2table_p %>% left_join(admin2coverage %>% dplyr::select(-matches("jmmi|aor|Governorate|government_ID|District$")), by=c("date2"="Date", "district_ID"="district_ID"))
Admin2data_current <- Admin2table %>% arrange(desc(date2)) %>% dplyr::filter(date2 == max_date) # subset only recent month dates to attach to shapefile
currentD <- as.character(format(max(Admin2table$date2),"%B %Y")) # define current date for disply in dashboard
#National
AdminNatTable <- AdminNatData %>% mutate_at(vars(-matches("date|aor")), ~ round(as.numeric(.)), 0) %>%
mutate(date2 = as.Date(as.yearmon(date)))
AdminNatData_current <- AdminNatTable %>% arrange(desc(date2)) %>% dplyr::filter(date2 == max_date) # subset only recent month dates to attach to shapefile
currentD <- as.character(format(max(AdminNatTable$date2),"%B %Y")) # define current date for display in dashboard
# Price long data for Plot tab
prices <- Admin2table %>%
dplyr::select(date2, government_name:district_ID, everything(), -date, -government_ID, -district_ID, -aor) %>%
dplyr::rename(Date=date2, Governorate=government_name, District=district_name)
prices_long <- prices %>%
tidyr::pivot_longer(cols = 4:ncol(.)) %>%
dplyr::rename(Item=name, Price=value)
prices_long <- prices_long %>% rbind(indicators_long) ## For the plot tab
data <- Admin2table %>% ## for the data explorer tab
dplyr::rename(Date=date, Governorate=government_name, District=district_name)
##-------------------------- SPATIAL DATA WRANGLE ----------------------
# Read in shapefiles
Admin1<- readOGR("./www", "YEM_adm1_Governorates")
Admin2<- readOGR("./www", "YEM_adm2_Districts")
Admin1@data$admin1name<-gsub("Amanat Al Asimah", "Sana'a City", Admin1@data$admin1name)
Admin1@data$admin1refn<-gsub("Amanat Al Asimah", "Sana'a City", Admin1@data$admin1refn)
Admin2@data$admin1name<-gsub("Amanat Al Asimah", "Sana'a City", Admin2@data$admin1name)
Admin2@data<- Admin2@data %>% dplyr::mutate_if(is.factor, as.character)
##-------------------------- COMBINE TABULAR & SPATIAL DATA----------------------
#Merge data from Google Sheet with Rayon shp file
# Rshp <- merge(x=Admin2,y=Admin2data_current, by.x="admin2pcod", by.y= "district_ID")
Rshp <- sp::merge(x=Admin2,y=Admin2table, by.x="admin2pcod", by.y= "district_ID", duplicateGeoms = TRUE,no.dups = FALSE )
Rshp <- Rshp[!is.na(Rshp$date2),] # filter out NAs date
Rshp <- st_simplify(st_as_sf(Rshp), dTolerance = 0.5)
Rshp <- st_transform(x = Rshp, crs = "+proj=longlat +ellps=WGS84 +no_defs")
Rshp <- as(Rshp,"Spatial")
Admin1 <- st_simplify(st_as_sf(Admin1), dTolerance = 0.5)
Admin1 <- st_transform(x = Admin1, crs = "+proj=longlat +ellps=WGS84 +no_defs")
Admin1 <- as(Admin1,"Spatial")
##-------------------------- CREATE MAP LABELS ----------------------
#GOVERNORATE LABELS
# Get polygons centroids
centroids <- as.data.frame(centroid(Admin1))
colnames(centroids) <- c("lon", "lat")
centroids <- data.frame("ID" = 1:nrow(centroids), centroids)
# Create SpatialPointsDataFrame object
coordinates(centroids) <- c("lon", "lat")
proj4string(centroids) <- sp::proj4string(Admin1) # assign projection
centroids@data <- sp::over(x = centroids, y = Admin1, returnList = FALSE)
centroids1 <- as.data.frame(centroid(Admin1))
colnames(centroids1) <- c("lon", "lat")
centroids@data <- cbind(centroids@data, centroids1)
## For drop down selection in data explorer and plot tabs
cols <- c("rgb(238,88,89)", "rgb(88,88,90)", "rgb(165,201,161)", # define color palette for plot lines
"rgb(86,179,205)", "rgb(246,158,97)", "rgb(255,246,122)",
"rgb(210,203,184)", "rgb(247,172,172)", "rgb(172,172,173)",
"rgb(210,228,208)", "rgb(171,217,230)", "rgb(251,207,176)",
"rgb(255,251,189)", "rgb(233,229,220)")
################# Import indicator list with all labels for app #################
## DROP DOWN MENU SELECTIONS for Plot & Data Explorer + map parameters
## A. Code below to produce the base for the indicator list. Should be commented unless you lost the original file for some reason.
# vars <- c("SMEB"="SMEB", "SMEB Water"="WASH_SMEB", "SMEB Food"="Food_SMEB","Daily wage"="daily_wage_rate",
# "Parallel Exchange Rates"="exchange_rates",
# "Wheat Flour" = "wheat_flour", "Rice" = "rice", "Dry Beans" = "beans_dry", "Canned Beans" = "beans_can", "Lentils" = "lentil",
# "Vegetable Oil" = "vegetable_oil", "Sugar" = "sugar", "Salt" = "salt", "Potato" = "potato", "Onion" = "onion",
# "Petrol" = "petrol", "Diesel" = "diesel",
# "Bottled Water"="bottled_water", "Treated Water"="treated_water", "Water Trucking"= "cost_cubic_meter",
# "Soap"="soap", "Laundry Powder"="laundry_powder", "Sanitary Napkins"="sanitary_napkins", "Bleach"="bleach", "Cooking gas"="cooking_gas")
# vars_functionnality <- colnames(indicators)[!colnames(indicators) %in% c("Date", "Governorate", "District")]
# replace.name <- c("mrk_increse_food_100"="If the demand for food items were to increase by 100%, would you be able to respond to this increase?",
# "mrk_increse_food_50"="If the demand for food items were to increase by 50%, would you be able to respond to this increase?",
# "mrk_increse_fuel_100"="If the demand for fuel items were to increase by 100%, would you be able to respond to this increase?",
# "mrk_increse_fuel_50"="If the demand for fuel items were to increase by 50%, would you be able to respond to this increase?",
# "mrk_increse_wash_100"="If the demand for WASH items were to increase by 100%, would you be able to respond to this increase?",
# "mrk_increse_wash_50"="If the demand for WASH items were to increase by 50%, would you be able to respond to this increase?",
# "mrk_increse_water_100"="If the demand for water trucking were to increase by 100%, would you be able to respond to this increase?",
# "mrk_increse_water_50"="If the demand for water trucking were to increase by 50%, would you be able to respond to this increase?",
# "mrk_supply_issues.dmg_storage"="Supply issues: Destruction/damage to storage capacity",
# "mrk_supply_issues.move_restriction"="Supply issues: Movement restrictions (check points, curfews, roadblocks, etc)",
# "mrk_supply_routes"="Have supply routes changed in a way harmful to your business in the past 30 days?",
# "water_chlorinated"="Is the water from water trucking chlorinated?",
# "distance_price"="Do you charge different prices depending on the distance you must travel to deliver water?",
# "additional_cost_5"="For an order of 5 km for the full truck, what is the additional cost of delivery? (in YER)",
# "additional_cost_10"="For an order of 10 km for the full truck, what is the additional cost of delivery? (in YER)",
# "additional_cost_20"="For an order of 15 km for the full truck, what is the additional cost of delivery? (in YER)",
# "additional_cost_30"="For an order of 20 km for the full truck, what is the additional cost of delivery? (in YER)")
# names_vars_functionnality <- stringr::str_replace_all(vars_functionnality, replace.name) %>% gsub("_", " ", .) %>% gsub("sell", "% of vendors selling",.)
# n_mkt_fun <- length(vars_functionnality)
# title.legend <- c("SMEB Cost", "WASH SMEB Cost", "Food SMEB Cost", "Daily wage (YER)",
# "YER to 1 USD",
# "Price (1 Kg)", "Price (1 Kg)", "Price (10 Pack)", "Price (15oz can)","Price (1 Kg)",
# "Price (1 L)", "Price (1 Kg)", "Price (1 Kg)", "Price (1 Kg)", "Price (1 Kg)",
# "Price (1 L)", "Price (1 L)",
# "Price (0.75 L)", "Price (10 L)", "Price (18.8kg)",
# "Price (100 g)", "Price (100 g)", "Price (10 Pack)", "Price (Cubic m)", "Price (1 L)",
# rep(" % of traders", n_mkt_fun))
# unit <- c(rep(" YER", 25), rep(" %", n_mkt_fun))
# indicator_group <- c(rep("I. Indices", 4),
# "II. Currencies",
# rep("III. Food items", 10),
# rep("IV. Fuels", 2),
# rep("V. Water", 3),
# rep("VI. Non-food items", 5),
# rep("VII. Other indicators", n_mkt_fun))
# variables <- c(unname(vars), vars_functionnality)
# Item <- c(names(vars), names_vars_functionnality)
# Item2 <- stringr::str_wrap(Item, width = 45) # To wrap the choices that are too large in the drop down menu
# Item2 <- stringr::str_replace_all(Item2, "\\n", "<br>")
#
# indicator_list <- data.frame(Item=Item, ## Building the indicator list with labels
# Item2=Item2,
# Variable=variables,
# Group = indicator_group,
# Legend = title.legend,
# Unit = unit) %>%
# mutate(Legend=ifelse(str_detect(Variable, "additional_cost"), "Cost (YER)", Legend),
# Unit=ifelse(str_detect(Variable, "additional_cost"), "YER", Unit))
# indicator_list %>% write.xlsx("indicator_list_out.xlsx")
## B. Import the indicator list which maps variable names with label names, category and unit for layout in the dashboard
# If you have a new item, update it in the file before running the line below.
# Add the new item as a new row in the excel file in the corresponding order as you want it to appear in the drop down list in the dashboard.
indicator_list <- read.xlsx("indicator_list.xlsx", sheet = 1)
indicator_group <- indicator_list$Group
## Setting custom maps color palettes for all items:
pal_red <<- colorRamp(c("#FEF2F2", "#F7B7B7", "#EE5859", "#8F3535", "#471A1A"), interpolate="linear")
pal_blue <<- colorRamp(c("#EEF3F8", "#B6CBDF", "#0067A9", "#004876", "#002844"), interpolate="linear")
pal_green <<- colorRamp(c("#E7ECE6", "#C1CFBF", "#72966E", "#50694D", "#2D3B2C"), interpolate="linear")
pal_yellow <<- colorRamp(c("#FFFDDD", "#FFF9A9", "#FFF67A", "#B2AC55", "#666231"), interpolate="linear")
palette <- c(rep("pal_blue", length(indicator_group[indicator_group %in% c("I. Indices", "II. Currencies", "V. Water")])),
rep("pal_green", length(indicator_group[indicator_group %in% c("III. Food items")])),
rep("pal_red", length(indicator_group[indicator_group %in% c("IV. Fuels", "VI. Non-food items")])),
rep("pal_yellow", length(indicator_group[indicator_group %in% c("VII. Other indicators")]))) %>% lapply(get)
# Adding the color palette to the indicator list for the map
indicator_list <- indicator_list %>% mutate(Palette = I(palette))
# Uncomment the below line to keep a trace of the indicator list for archive
# write.xlsx(indicator_list %>% dplyr::select(-Palette), "indicator_list_out.xlsx")
plot_location_list <- Admin2table %>% ungroup %>% # Define location list
dplyr::rename(Governorate=government_name, District=district_name) %>%
dplyr::select(Governorate, District) %>%
arrange(Governorate, District) %>%
dplyr::filter(!duplicated(District))
dates <- sort(unique(Admin2table$date2)) # define list with date range in data
dates_min <- as.Date("2020-01-01") # set minimum date to be displayed
dates_max <- max(Admin2table$date2, na.rm = T) # maximum date in data
dates_max2 <- sort(unique(Admin2table$date2), decreasing=T)[2] # second-latest date
dates.non.na <- Admin2table %>% dplyr::select(-any_of(c("date", "aor")), -matches("government|district")) %>%
tidyr::pivot_longer(2:ncol(.)) %>% dplyr::group_by(date2, name) %>%
dplyr::mutate(value=paste(unique(value), collapse=";"), is.na=ifelse(value=="NA", T, F)) %>% dplyr::filter(is.na) %>% dplyr::distinct() %>%
dplyr::left_join(indicator_list %>% dplyr::select(Item, Variable), by=c("name"="Variable"))
dates_max_1y <- as.POSIXlt(dates_max) # most recent month minus 1 year
dates_max_1y$year <- dates_max_1y$year-1
dates_max_1y <- as.Date(dates_max_1y)
# Prepare tables for dashboard tab
prices_country <- prices %>% # aggregate price data at country level
dplyr::select(-Governorate, -District, -matches("^n_")) %>%
dplyr::select(Date:num_obs, matches("SMEB"), -num_obs) %>%
dplyr::group_by(Date) %>%
dplyr::summarise_all(median, na.rm = TRUE)
prices_country_long <- tidyr::gather(prices_country, Item, Price, 2:ncol(prices_country))# transform country-level price data to long format
prices_country_home <- prices_country %>% # filter out SMEB data from country level price data
dplyr::filter(Date >= dates_min) %>%
dplyr::select(Date, SMEB, Food_SMEB, WASH_SMEB) %>%
tidyr::gather(Item, Price, SMEB:WASH_SMEB) %>% # transform SMEB data to long format so highcharter can read dataframe
dplyr::mutate(Item = gsub("_", " ", Item))
prices_changes <- prices_country_long %>% # calculate bi-monthly/yearly changes of item prices
dplyr::filter(Date == dates_max | Date == dates_max2 | Date == dates_max_1y) %>%
dplyr::group_by(Item) %>%
dplyr::mutate(change = scales::percent(Price/lag(Price, order_by=Date)-1, accuracy = 1),
change2 = scales::percent(Price/lag(Price, n = 2, order_by=Date)-1, accuracy = 1)) %>%
dplyr::mutate(change = ifelse(!grepl('^\\-', change) & change != "0%" & !is.na(change), paste0("+", change, HTML(" ▲")), change),
change = ifelse(grepl('^\\-', change), paste0(change, HTML(" ▼")), change),
change = ifelse(change == "0%", paste0(change, HTML(" ▶")), change),
change2 = ifelse(!grepl('^\\-', change2) & change2 != "0%" & !is.na(change2), paste0("+", change2, HTML(" ▲")), change2),
change2 = ifelse(grepl('^\\-', change2), paste0(change2, HTML(" ▼")), change2),
change2 = ifelse(change2 == "0%", paste0(change2, HTML(" ▶")), change2)) %>%
dplyr::filter(Date == dates_max, !is.na(Price)) %>%
dplyr::select(-Date) %>%
dplyr::mutate(Price = format(Price, big.mark=","),
change2 = tidyr::replace_na(change2, "NA")) %>%
dplyr::rename("Price (in YER)" = Price,
"Bi-monthly change" = change,
"Yearly change" = change2) %>%
left_join(indicator_list %>% dplyr::select(Item, Variable, Group), by=c("Item"="Variable")) %>% ungroup %>%
dplyr::select(-Item) %>% dplyr::rename(Item=Item.y) %>% dplyr::relocate(Item, .before=1)
prices_changes_items <- prices_changes %>%
dplyr::filter(!str_detect(Item, "SMEB|Parallel Exchange Rates|Daily wage")) %>%
arrange(Group) %>% dplyr::select(-Group)
prices_changes_meb <- prices_changes %>%
dplyr::filter(str_detect(Item, "SMEB|Parallel Exchange Rates|Daily wage")) %>%
dplyr::arrange(Group, desc(Item)) %>% dplyr::mutate(Item=gsub("Parallel Exchange Rates","US dollar (1 USD)", Item))
data_latest <- full_data %>% # latest dataset for download on dashboard page
dplyr::filter(Date == dates_max) %>%
dplyr::select(-aor)
month_collected <- paste0(format(dates_max, "%B"), " ",format(dates_max, "%Y")) # define overview of last round
shops_covered <- nrow(data_latest)
districts_covered <- n_distinct(data_latest$District, na.rm = FALSE)
governorates_covered <- n_distinct(data_latest$Governorate, na.rm = FALSE)
overview_round <- data.frame(figure = c("Traders interviewed", "Districts covered", "Governorates covered"),
value = c(shops_covered, districts_covered, governorates_covered))
table_round <- overview_round %>% # style overview table
kbl(escape = F, format.args = list(big.mark = ","), align = "lr", col.names = NULL) %>%
column_spec(1, width = "12em") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), fixed_thead = T, full_width = T) %>%
row_spec(1, extra_css = "font-size: 11.5px; border-top: 2px solid gainsboro") %>%
row_spec(2:nrow(overview_round), extra_css = "font-size: 11.5px;")
table_changes <- prices_changes_items %>% # style item table
kbl(escape = F, format.args = list(big.mark = ","), align = "lrrr") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), fixed_thead = T, full_width = F) %>%
column_spec(1, width = "12em") %>%
column_spec(3, color = ifelse(grepl('^\\+', prices_changes_items$'Bi-monthly change'), "red", ifelse(grepl('^\\-', prices_changes_items$'Bi-monthly change'), "green", "auto"))) %>%
column_spec(4, color = ifelse(grepl('^\\+', prices_changes_items$'Yearly change'), "red", ifelse(grepl('^\\-', prices_changes_items$'Yearly change'), "green", "auto"))) %>%
pack_rows("Food Items", 1, 10, label_row_css = "background-color: #f5f5f5; font-size: 10.5px; border-top: 2px solid gainsboro") %>%
pack_rows("Fuels & Water", 11, 15, label_row_css = "background-color: #f5f5f5; font-size: 10.5px; border-top: 2px solid gainsboro") %>%
# pack_rows("Water", 13, 15, label_row_css = "background-color: #f5f5f5; font-size: 10.5px; border-top: 2px solid gainsboro") %>%
pack_rows("Non-Food Items", 16, 20, label_row_css = "background-color: #f5f5f5; font-size: 10.5px; border-top: 2px solid gainsboro") %>%
row_spec(0:nrow(prices_changes_items), extra_css = "font-size: 11px;") %>%
scroll_box(height="90%")
# Dashboard tables
smeb <- data.frame(Category = c(rep("WASH SMEB", 4), rep("Food SMEB", 5), "Non-food items & shelter", "Services"), # define SMEB content table
Item = c("Soap", "Laundry powder", "Sanitary Napkins", "Cubic meter water",
"Wheat flour", "Beans dry","Vegetable oil", "Sugar", "Salt", "NFI & shelter lumpsum", "Services lumpsum"),
Quantity = c("10.5 ", "2 Kg", "5 Boxes", "3.15 m^3", "7.5 Kg", "10 ", "8 ", "2.5 ", "1Kg",
"North: 25'000 YER\nSouth: 28'750 YER", "North: 19'000 YER \nSouth: 21'850 YER"))
smeb_kbl <- smeb %>% # make a html (kable) object out of dataframe
kbl(escape = F) %>%
kable_styling(bootstrap_options = c("hover", "condensed", "striped"), fixed_thead = T, full_width = F) %>%
column_spec(1, width = "9em", bold = T, background = "white") %>%
column_spec(2, width = "10em") %>%
column_spec(3, width = "13em") %>%
collapse_rows(columns = 1, valign = "top") %>%
row_spec(0:nrow(smeb), extra_css = "font-size: 11px;")
table_changes_meb <- prices_changes_meb %>% dplyr::select(-Group) %>% # style key figures table
kbl(escape = F, format.args = list(big.mark = ","), align = "lrrr") %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"), fixed_thead = T, full_width = F) %>%
column_spec(1, width = "9em") %>%
column_spec(3, color = ifelse(grepl('^\\+', prices_changes_meb$'Bi-monthly change'), "red", ifelse(grepl('^\\-', prices_changes_meb$'Bi-monthly change'), "green", "auto"))) %>%
column_spec(4, color = ifelse(grepl('^\\+', prices_changes_meb$'Yearly change'), "red", ifelse(grepl('^\\-', prices_changes_meb$'Yearly change'), "green", "auto"))) %>%
row_spec(0:nrow(prices_changes_meb), extra_css = "font-size: 11px;")
varsDate <- c("Months to Select" = "varDateSelect")
# Partners logo table
# logo.partners <- list.files(path="www/partners")
partners <- read.xlsx("partners.xlsx")
partners.active <- partners %>% filter(active==1) %>%
dplyr::mutate(group = c(rep(0, 10), rep(1, nrow(.)-10))) %>% split(.$group)
partners.past <- partners %>% filter(active==0) %>%
dplyr::mutate(group = c(rep(0, 10), rep(1, nrow(.)-10))) %>% split(.$group)
# partners.active <- partners %>% filter(active==1) %>% split(., rep(1:ceiling(nrow(.)/(nrow(.)/1)), each=(nrow(.)/1), length.out=nrow(.)))
# partners.past <- partners %>% filter(active==0) %>% split(., rep(1:ceiling(nrow(.)/(nrow(.)/2)), each=(nrow(.)/2), length.out=nrow(.)))
# partners <- partners %>%
# mutate(group = c(rep(0,9), rep(1,8), rep(2, 7), rep(3, nrow(.)-(9+8+7)))) %>%
# split(., .$group) # split partners logo file according to image size to fit box
############ UI ######################################################
# UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI UI
ui <- tagList( # fillPage( before => if layout issue go back to this
navbarPage("REACH: Yemen Joint Market Monitoring Initiative (JMMI)",
collapsible = T, windowTitle = "REACH: Yemen Joint Market Monitoring Initiative (JMMI)", # Title for browser tab window
#### * 6.1 Dashboard ######################################################################
tabPanel("Dashboard", # define panel title
icon = icon("tachometer-alt"), # select icon to be displayed in front of title
tags$head(shiny::includeCSS("styles.css") # Include our custom CSS
# , style =" {overflow-y: scroll; }"
),
div(class="dashboard", # set dashboard class from CSS file
tags$head(shiny::includeCSS("styles_IRQ.css")), # load CSS stylesheet
leafletOutput("map_home", width = "100%", height = "100%"), # display background map
absolutePanel( # define introduction box
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor<-20), left = as.character(left<-12), right = "auto", bottom = "auto", width = "400", height = "320",
h4("Introduction"),
p("The Yemen Joint Market Monitoring Initiative (JMMI) is an initiative led by
REACH in collaboration with the Water, Sanitation, and Hygiene (WASH) Cluster
and the Cash and Markets Working Group (CMWG) to support humanitarian actors with
the harmonization of market monitoring throughout Yemen. It includes price monitoring
for ten food items and ten non-food items (NFIs), including fuel, water and hygiene products.",
style="text-align:justify"),
p(tags$i(h6("The JMMI would not be possible without the +30 partner organisations who currently collect data, or have collected data in the past!", style="color:grey;text-align:justify"))),
p("List of partners:"),
),
absolutePanel( # define chart box
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor+335), left = as.character(left), right = "auto", bottom = "auto", width = "400", height = "270",
hchart(prices_country_home, "line", # define chart
hcaes(x = Date, y = Price, group = Item)) %>%
hc_yAxis(min = 0, title = list(text = "")) %>%
hc_xAxis(title = "", labels = list(align = "center")) %>%
hc_size(height = "253") %>%
hc_title(
text = "Overall Median SMEB Over Time (in YER)",
margin = 10,
align = "left",
style = list(fontSize = 15)
) %>%
hc_colors(cols) %>%
hc_legend(style = list(fontSize = 8))
),
absolutePanel(
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor), left = as.character(left+415), right = "auto", bottom = "auto", width = "340", height = "250",
h4(paste0("Key Figures", " (", format(dates_max, "%b"), " ", format(dates_max, "%Y"), ")")),
HTML(table_changes_meb), br()
),
absolutePanel(
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor+265), left = as.character(left+415), right = "auto", bottom = "auto", width = "340", height = "155",
h4("Latest Round Coverage"),
HTML(table_round), br()
),
absolutePanel(
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor+435), left = as.character(left+415), right = "auto", bottom = "auto", width = "340", height = "170",
h4("Data Download"),
# p("Visit the Data Explorer or download the full dataset from the latest round here:"),
downloadButton("downloadDataLatest", style = "font-size: 12px",
paste0("Download ", format(dates_max, "%B"), " ", format(dates_max, "%Y"), " dataset ")),
br(),
p(h4("Download the Situation Overview:")),
p(h5(tags$a(href="https://www.impact-repository.org/document/reach/e619a6e3/REACH_YEM_Situation-Overview_-Joint-Market-Monitoring-Initiative-JMMI_July2021.pdf",
paste0("JMMI Situation Overview ", month_collected)))),
# downloadButton("downloadFactsheet", style = "font-size: 12px",
# paste0("Download ", format(dates_max, "%B"), " ", format(dates_max, "%Y"), " situation overview")),
br()
),
absolutePanel(
id = "home", class = "panel panel-default", fixed = FALSE, draggable = FALSE,
top = as.character(ver.anchor), left = as.character(left+770), right = "auto", bottom = "auto",
width = "400", height = "605",
h4(paste0("Overall Median Item Prices", " (", format(dates_max, "%b"), " ", format(dates_max, "%Y"), ")")),
HTML(table_changes), br()
),
absolutePanel(id = "dropdown", top = as.character(ver.anchor+27), left = as.character(left+650), width = 200, fixed=FALSE, draggable = FALSE, height = "auto",
dropdown(
h4("SMEB contents"),
column(
HTML(smeb_kbl),
width = 6),
column(p(h6("Each month, enumerators conduct KI interviews with market vendors to collect three price quotations for each item from the same market in each district.
REACH calculates different the Food SMEB, WASH SMEB and estimation of the total SMEB using two lumpsum amounts to account for cost of services, non-food items and shelter.
The weight for each index is detailed in the table on the left.")),
p(h6("The calculation of the aggregated median price for districts and
governorates is done following a stepped approach. The median of all the price quotations collected is aggregated to calculate the district and the governorate median price.
Governorate medians are calculated using market level prices to keep granularity of data given the limited coverage of JMMI in Yemen.")),
p(h6("More details on the calculation of the SMEB can be found here:",
tags$a(href="https://www.humanitarianresponse.info/sites/www.humanitarianresponse.info/files/documents/files/cmwg_yemen_smeb_gn_final_27102020.pdf",
"SMEB Guidance Note"), ".")),
width = 5),
width = "650px",
tooltip = tooltipOptions(title = "Click for more details on the SMEB."),
size = "xs",
up = FALSE,
style = "jelly", icon = icon("info"),
animate = animateOptions(
enter = "fadeInDown",
exit = "fadeOutUp",
duration = 0.5)
)
),
absolutePanel(id = "partners", top = as.character(ver.anchor+278), left = as.character(left+125), width = 200, fixed=FALSE, draggable = FALSE, height = "auto",
dropdown(
h4("JMMI Partners"),
# column(p(h6("You can see the list of all of our Partners collecting data.")), width = 5),
# fillPage(fillRow(uiOutput("logopartners"))),
column(p(h5(paste0("Partners for ", month_collected, ":"))), width = 8),
fillPage(fillRow(uiOutput("logopartners.active"))),
br(),br(),br(),br(),br(),
column(p(h5(paste0("They contributed in the past:"))), width = 8),
fillPage(fillRow(uiOutput("logopartners.past"))),
br(),br(),br(),br(),br(),
width = "800px",
heigth = "3000px",
tooltip = tooltipOptions(title = "Click for more details on JMMI Partners."),
size = "xs",
up = FALSE,
style = "jelly", icon = icon("handshake"),
animate = animateOptions(
enter = "fadeInDown",
exit = "fadeOutUp",
duration = 0.5)
)
),
absolutePanel(id = "logo", class = "card", bottom = 10, left = as.character(left),
# left = 1200, top = as.character(v.anch<-740),
fixed=TRUE, draggable = FALSE, height = "auto",
tags$a(href='https://www.reach-initiative.org', target = "_blank", tags$img(src='reach_logoInforming.jpg', height='40'))),
absolutePanel(id = "logo", class = "card", bottom = 10, left = as.character(left+180),
# left = 1320, top = as.character(v.anch),
fixed=TRUE, draggable = FALSE, height = "auto",
tags$a(href='https://www.humanitarianresponse.info/sites/www.humanitarianresponse.info/files/documents/files/cmwg_yemen_smeb_gn_final_27102020.pdf', target = "_blank", tags$img(src='CMWG Logo.jpg', height='40'))),
absolutePanel(id = "logo", class = "card", bottom = 10, left = as.character(left+283),
# left = 1320, top = as.character(v.anch),
fixed=TRUE, draggable = FALSE, height = "auto",
tags$a(href='https://www.humanitarianresponse.info/en/operations/yemen/water-sanitation-hygiene', target = "_blank", tags$img(src='washlogo_grey-300DPI.png', height='40')))
# display partner logos on bottom
# absolutePanel(id = "logo", class = "card",
# # top = ver<-v.anch+60,
# top = ver<-800,
# left = (anchor<-45), fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.acted.org/en/countries/yemen/', target = "_blank", tags$img(src='0_acted.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+75, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_almaroof.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+135, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://adra.org/', target = "_blank", tags$img(src='0_adra.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+180, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_thadamon.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+225, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_b4d.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+335, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='http://yfca.org/en/', target = "_blank", tags$img(src='0_yfca.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+410, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_ysd.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+440, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_vision.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+510, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.zoa-international.com/files/yemen/', target = "_blank", tags$img(src='0_zoa.PNG', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+580, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.facebook.com/sama.alyemen.5', target = "_blank", tags$img(src='0_sama.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+640, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.solidarites.org/en/missions/yemen/', target = "_blank", tags$img(src='0_si.jpeg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+690, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_tyf.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+790, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.nrc.no/countries/middle-east/yemen/', target = "_blank", tags$img(src='0_nrc.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver, left = anchor+880, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_steps.jpg', height='30'))),
#
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='http://bchr-ye.org/', target = "_blank", tags$img(src='0_bchr.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+55, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.facebook.com/cyf.org77/', target = "_blank", tags$img(src='0_cyf.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+95, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='http://www.drc.dk', target = "_blank", tags$img(src='0_drc.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+175, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.facebook.com/noqat.org/', target = "_blank", tags$img(src='0_gwq.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+215, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.iom.int/countries/yemen', target = "_blank", tags$img(src='0_iom.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+285, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.rescue.org/', target = "_blank", tags$img(src='0_IRC.jpg', height='30', length='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+330, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.mercycorps.org/where-we-work/yemen', target = "_blank", tags$img(src='0_mercy.jfif', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+360, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='http://nfdhr.org/', target = "_blank", tags$img(src='0_nfdhr.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+420, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_nfhd.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+505, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.oxfam.org/en/tags/yemen', target = "_blank", tags$img(src='0_oxfam.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+600, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://yemen.savethechildren.net/', target = "_blank", tags$img(src='0_sci.png', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+725, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='', target = "_blank", tags$img(src='0_ocfd.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+770, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://www.facebook.com/TamdeenYouth/', target = "_blank", tags$img(src='0_soul.jpg', height='30'))),
#
# absolutePanel(id = "logo", class = "card", top = ver+40, left = anchor+910, fixed=TRUE, draggable = FALSE, height = "auto",
# tags$a(href='https://rocye.org/', target = "_blank", tags$img(src= '0_roc.jpg', height='30')))
) # close dashboard class
),
#### * 6.2 Map ######################################################################
tabPanel("Map", #TAB LABEL
icon= icon("map"), # TAB ICON
div(class="outer",
tags$head(
# Include our custom CSS
shiny::includeCSS("AdminLTE.css"),
shiny::includeCSS("bootstrap.css"), # added
shiny::includeCSS(path = "shinydashboard.css"),
# br() # added => was causing an issue by adding whitespace at the beginning of the page
),
#LEAFLET MAP
# If not using custom CSS, set height of leafletOutput to a number instead of percent
leaflet::leafletOutput("map1", width="100%", height="100%"), # BRING IN LEAFLET MAP, object created in server.R
tags$head(tags$style(".leaflet-control-zoom { display: none; }
#controls {height:90vh; overflow-y: auto; }
")), # remove map zoom controls
tags$head(tags$style(
type = "text/css",
"#controlPanel {background-color: rgba(255,255,255,0.8);}",
".leaflet-top.leaflet-left .leaflet-control {
margin-top: 25px;
}"
)),
# https://stackoverflow.com/questions/37861234/adjust-the-height-of-infobox-in-shiny-dashboard
#SIDE PANEL
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = 1,
# width = 500,
width = "35%",
height = "auto",
hr(),
h5(tags$u("Most recent findings displayed in map are from data collected in ", #DistsNumn and currentD will change based on the most recent JMMI, defined in global.R
tags$strong(districts_covered), "districts in ", tags$strong(paste0(currentD,".")))),
h5("Further details regarding the JMMI methodology and the Survival Minimum Expenditure Basket (SMEB) calculation can be found on the information tab."),
hr(),
pickerInput("variable1",
label = "Select a variable below to enable the map",
choices = lapply(split(indicator_list$Item, indicator_list$Group), as.list),
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = "SMEB",
multiple = FALSE,
choicesOpt = list(content = indicator_list$Item2)
),
sliderTextInput("date_map", # set date slider
"Month:",
force_edges = TRUE,
choices = dates,
selected = dates_max,
animate = TRUE
),
h5(textOutput("text3")), #extra small text which had to be customized as an html output in server.r (same with text1 and text 2)
# h5(textOutput("text1000")),
#HIGH CHART
highchartOutput("hcontainer", height= 300, width = "100%"),
#new data table
hr(),
selectInput(inputId= "varDateSelect", label = h4("Select Month of Data Collection"), choices=NULL, selected = (("varDateSelect"))), # linked date stuff
h5("Please select a district to enable month selection"),
h5(textOutput("text_DT")),
DT::dataTableOutput("out_table_obs",height = "auto", width = "100%"),
#####Attempt to add an info box
hr(),
h5("Exchange Rate for selected month"),
h5("Please select month to populate the information box"),
fluidRow(valueBoxOutput("info_exchange", width = 12)),
hr(),
#hr(),
h6(htmlOutput("text1")),
h6(htmlOutput("text2")),
h6(htmlOutput("text4")),
column(width=12, align="center", div(id="cite2", "Funded by: "), img(src='DFID UKAID.png', width= "90px"),img(src='[email protected]', width= "90px"),
img(src='USAID.png', width= "105px")) #donor logos
),
tags$div(id="cite",
a(img(src='reach_logoInforming.jpg', height= "40px"), target="_blank", href="http://www.reach-initiative.org"),
img(src='CMWG Logo.jpg', height= "40px", style='padding:1px;border:thin solid black;'),
img(src='washlogo_grey-300DPI.png', height= "40px"))
)
),
#### Plot ######################################################################
tabPanel("Plot", # set panel title
icon = icon("chart-line"), # select icon
chooseSliderSkin(skin = "Flat", color = NULL), # set theme for sliders
sidebarLayout(
sidebarPanel(
tags$i(h6("Note: Reported prices are indicative only.", style="color:#045a8d")),
pickerInput("plot_aggregation",
label = "Aggregation level:",
choices = c("District", "Governorate", "Country"),
selected = "Country",
multiple = FALSE
),
conditionalPanel(condition = "input.plot_aggregation == 'Country'",
radioGroupButtons("plot_type",
label = "Plot type:",
choices = c("Line Graph", "Boxplot"),
selected = "Line Graph",
justified = TRUE
)
),
hr(),
conditionalPanel(condition = "input.plot_aggregation == 'District'",
radioGroupButtons("plot_by_district_item",
label = "Group by:",
choices = c("Item", "District"),
selected = "Item",
justified = TRUE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'Governorate'",
radioGroupButtons("plot_by_governorate_item",
label = "Group by:",
choices = c("Item", "Governorate"),
selected = "Item",
justified = TRUE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'District' & input.plot_by_district_item == 'District'",
pickerInput("select_bydistrict_district",
label = "District(s):",
choices = lapply(split(plot_location_list$District, plot_location_list$Governorate), as.list),
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = c("Al Mansura"),
multiple = TRUE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'District' & input.plot_by_district_item == 'District'",
pickerInput("select_bydistrict_item",
label = "Item:",
# choices = lapply(split(indicator_list$Item, indicator_list$Group), as.list)[1:6],
choices = lapply(split(indicator_list$Variable, indicator_list$Group), as.list)[1:6],
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = "Food_SMEB",
choicesOpt = list(content = indicator_list$Item2),
multiple = FALSE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'Governorate' & input.plot_by_governorate_item == 'Governorate'",
pickerInput("select_bygovernorate_governorate",
label = "Governorate(s):",
choices = unique(plot_location_list$Governorate),
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = c("Aden"),
multiple = TRUE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'Governorate' & input.plot_by_governorate_item == 'Governorate'",
pickerInput("select_bygovernorate_item",
label = "Item:",
# choices = lapply(split(indicator_list$Item, indicator_list$Group), as.list)[1:6],
choices = lapply(split(indicator_list$Variable, indicator_list$Group), as.list)[1:6],
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = "Food_SMEB",
choicesOpt = list(content = indicator_list$Item2),
multiple = FALSE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'Country' | (input.plot_aggregation == 'Governorate' & input.plot_by_governorate_item == 'Item') | (input.plot_aggregation == 'District' & input.plot_by_district_item == 'Item')",
pickerInput("select_byitem_item",
label = "Item(s):",
# choices = lapply(split(indicator_list$Item, indicator_list$Group), as.list)[1:6],
choices = lapply(split(indicator_list$Variable, indicator_list$Group), as.list)[1:6],
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = c("SMEB", "Food_SMEB", "WASH_SMEB"),
choicesOpt = list(content = indicator_list$Item2),
multiple = TRUE
)
),
conditionalPanel(condition = "input.plot_aggregation == 'District' & input.plot_by_district_item == 'Item'",
pickerInput("select_byitem_district",
label = "District:",
choices = lapply(split(plot_location_list$District, plot_location_list$Governorate), as.list),
options = list(title = "Select", `actions-box` = TRUE, `live-search` = TRUE),
selected = "Al Mansura",