-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.R
More file actions
2097 lines (1601 loc) · 84 KB
/
server.R
File metadata and controls
2097 lines (1601 loc) · 84 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
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
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# Programme SERVER
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
library( maptools )
library( xts )
###--------------------Création de quelques fonctions utiles dans server.R -----------------------###
# Renvoie le nom de la région
getname.region <- function( Region ){
res <- correspondance_nomreg_codereg$Nom_region[ match(Region, correspondance_nomreg_codereg$Region) ]
return( ifelse( is.na(res), Region, res ) )
}
# Capitalize the first letter
cap <- function( s ) {
paste( toupper( substring(s, 1, 1) ), substring(s, 2), sep="" )
}
# Uncapitaize the first letter
uncap <- function( s ) {
paste( tolower( substring(s, 1, 1) ), substring(s, 2), sep="" )
}
gvisMerge2 <- function( x, y ){
gvisMerge(x, y, horizontal=T, tableOptions = "class=TableGauge" ) #
}
addGvisATLTitle <- function(gvisATL,title) {
if (!all(class(gvisATL) == c("gvis","list"))) {
stop('ERROR in addGvisATLTitle: Incorrect type, expect gvisAnnotatedTimeLine.')
}
if (class(title) == "character") {
gvisATL$html$chart['divChart'] <- paste(title,gvisATL$html$chart['divChart'],sep="")
} else if (class(title) == "shiny.tag") {
gvisATL$html$chart['divChart'] <- paste(as.character(title)[1],gvisATL$html$chart['divChart'],sep="")
} else {
stop('ERROR in addGvisATLTitle: Unknown title type.')
}
return(gvisATL)
}
# Représentation graphique
add_shades <- function(x, periods, ...) {
for( period in periods ) {
x <- dyShading(x, from = period$from, to = period$to, ... )
}
x
}
# Looking for epidemic periods - only for weekly data
# dd : data.table
# epid : character, nom de la colonne contenant le statut épidéique 0/1
search.epidemic.period <- function( dd, epid="alarme_Serfling" ) {
TMP <- dd[ dd[[ (epid) ]]==1, ]$d
Periode <- rep(0,length(TMP))
Periode[1] <- 1
# If more than 1 epidemic week, looking for the different epidemic periods
if( length(TMP)>1 ){
for (i in 2:length(TMP)) {
# If epidemic week i is next in time to epidemic week i-1
if (TMP[i]==TMP[i-1]+7) {
Periode[i] <- Periode[i-1]
}
else Periode[i] <- Periode[i-1]+1
}
}
bigLL <- list()
for( i in 1:length(unique(Periode)) ) {
bigLL[[i]] <- list(from=min(TMP[Periode==i]),to=max(TMP[Periode==i]+7))
}
return( bigLL )
}
# Styling function for text output (strong blue character strings)
hh <- function( text ){
HTML('<span style="color:#181866; font-weight: bold;">', text, '</span>' )
}
###-------- Chargement des données pour toutes les sessions ----------------------###
# Label des noms de region
correspondance_nomreg_codereg <- fread( "Data/correspondance_codereg_nomreg.csv", encoding="UTF-8", colClasses="character")
setkey( correspondance_nomreg_codereg, Region )
###### Fichier des seuils pour les couleurs des cartes d'intensité
seuils_carte <- fread( "Data/seuils_cartes.csv", encoding="UTF-8")
############## Fonds de carte ##############
mapdir <- "Data/Fonds_de_carte/France_DOM_Mayotte_StBarth_StMartin_Regions"
# Fonds de carte Anciennes regions
map.fr_regionsA <- readShapePoly( paste( mapdir, "Region_France_DOM_2012_tt", sep='/') )
centro_regionsA <- readShapePoints( paste( mapdir, "XYRegion_DOM_2012_tt", sep='/') )
# Fonds de carte Nouvelles regions
map.fr_regionsN <- readShapePoly( paste( mapdir, "New_Regions_DOM", sep='/') )
centro_regionsN <- readShapePoints( paste( mapdir, "XYNew_Region_DOM", sep='/') )
# Couleur des proportions
#coul.prop <-c( "#fef0d9", "#fdcc8a", "#fc8d59", "#d7301f" )
#coul.prop <-c( "#eff3ff", "#bdd7e7", "#6baed6", "#2171b5" ) #
coul.prop <-c( "#bdd7e7","#6baed6", "#3182bd", "#08519c" )
# Couleur des alarmes
coul.alarme <- c("#19BA00", "#FF9900", "#FF0000" ) #c("green", "orange", "red") #2ca25f c("#a1d99b", "#feb24c", "#de2d26" )
# rgb(255,191,0, max = 255)
# Couleur des jauges
coul.jauge <- c( "#efedf5", "#bcbddc", "#756bb1" )
# Couleur des heatmap
coul.heatmap <- c( coul.alarme, "#808080" )
# Label des unites
typenom <- c("SAU", "Sentinelles", "SOS")
typeacte <- c( "visits", "consultations", "consultations" )
typedeno <- c( "10,000 emergency room visits", "100,000 inhabitants", "10,000 SOS Médecins consultations" )
names( typeacte ) <- typenom
names( typedeno ) <- typenom
###### Fichiers de correspondance code INSEE de region - numero region POUR LES REGIONS ANCIENNES
corresp_nom_num_regionsA <- fread("Data/correspondance_coderegold_numregold_pour_carte.csv", encoding="UTF-8", colClasses=list(character=1) )
corresp_nom_num_regionsN <- fread("Data/correspondance_coderegnew_numregnew_pour_carte.csv", encoding="UTF-8", colClasses=list(character=1))
########## Chargement des données de surveillance ##########
# Lectures des données hebdo
Data_week <- readRDS( "Data/Donnees_Sursaud_Sentinelles/Data_week.rds" )
#saveRDS( Data_week[ d>as.Date("2016-01-01") ], "Data/Donnees_Sursaud_Sentinelles/Data_week.rds" )
Data_week[ d > lastsunday, Dates:=paste(Dates, "INCOMPLETE")]
# Mise à jour des listes de choix des champs selects, lues dans la base hebdo
Liste_RS <- levels( Data_week$RS )
#write.csv2( data.frame( key=Liste_RS, fr=Liste_RS, en=Liste_RS), file="liste_rs.csv",quote = F, row.names=F )
Liste_regionsA <- unique( Data_week$Region[ Data_week$Region %in% corresp_nom_num_regionsA$code_reg ] )
names( Liste_regionsA ) <- getname.region( Liste_regionsA )
Liste_regionsA <- Liste_regionsA[ order(names(Liste_regionsA) ) ]
Liste_regionsN <- unique( Data_week$Region[ Data_week$Region %in% corresp_nom_num_regionsN$code_reg ] )
names( Liste_regionsN ) <- getname.region( Liste_regionsN )
Liste_regionsN <- Liste_regionsN[ order(names(Liste_regionsN) ) ]
# List of the possible analyzed zones for the corresponding radio button
List_analyzed_zones <- c("FRANCE", "METROPOLE", "regionsN", "regionsA")
# List of the possible mapped zones for the corresponding radio button
List_mapped_zones <- c("regionsN", "regionsA")
# List of the data source, the methods and the age classes for the select input fields.
List_sources <- sort( unique( Data_week$Source ) )
List_methods <- gsub( "alarme_", "", grep( "alarme_", names(Data_week), fixed=T, value=T ) )
List_ages <- sort( unique( Data_week$Classe_age ) )
#write.csv2( data.frame( age=List_ages ), row.names=F, file="age.csv" )
# Weekly alarm levels for a subset of dieases (winter pathologies)
alarm_level <- readRDS( "Data/Donnees_Sursaud_Sentinelles/alarm_level.rds" )
alarm_level[ d > lastsunday, Dates:=paste(Dates, "INCOMPLETE")]
# Weekly alarm list for this same subset
alarm_list <- readRDS( "Data/Donnees_Sursaud_Sentinelles/alarm_list.rds" )
# Lectures des données quotidiennes
#Data_day <- readRDS("Data/Donnees_Sursaud_Sentinelles/Data_day.rds")
# Lectures des données mensuelles
Data_month <- readRDS("Data/Donnees_Sursaud_Sentinelles/Data_month.rds")
# Description des variables pour les fichiers téléchargeables (résultats des méthodes de détection)
descMet <- fread( "Data/downloadMet_description_variables.csv", encoding="UTF-8" )
descNiv <- fread( "Data/downloadNiv_description_variables.csv", encoding="UTF-8" )
descMat <- fread( "Data/downloadMat_description_variables.csv", encoding="UTF-8" )
# Dictionnary dataset for the bilangual site
#lang_analyzedzones <- read.csv2( "Data/lang_analyzedzones.csv", as.is=TRUE, encoding="UTF-8")
#lang_mappedzones <- read.csv2( "Data/lang_mappedzones.csv", as.is=TRUE, encoding="UTF-8")
#lang_timeunits <- read.csv2( "Data/lang_timeunits.csv", as.is=TRUE, encoding="UTF-8")
# List of the time units available for analysis
#List_time_units <- c( "day", "week", "month" )
List_time_units <- c( "week", "month" )
# ----------------------------------------------------------------------------------------------------
shinyServer( function(input, output,session) {
getPlural <- function( text ){
n <- nchar( text )
if( substr(text, n, n) != "s" ){
text <- paste( text, "s", sep="" )
}
return( text )
}
cat("\n############################\n MASS \n #######################\n")
output$sessioninfo <- renderUI({
if(!is.null(input$packages)) sapply(input$packages, function(x) eval(parse(text=paste0("library(",x,")"))))
includeRmd("SessionInfo.Rmd")
})
############ Mise à jour de l'UI Regroupement syndromique en fonction des éléments de la bdd
#updateSelectizeInput( session, "RS", choices = getNamedList2( Liste_RS ), selected="Syndrome grippal" )
updateSelectizeInput( session, "RegionA", choices = Liste_regionsA )
updateSelectizeInput( session, "RegionN", choices = Liste_regionsN )
observe({
updateRadioButtons(session, "TimeUnit", choices=getNamedList2( List_time_units ), selected=input$TimeUnit, inline=T )
if( input$menu=="determination" ) {
cat( "\ninput$RS:", input$RS, "\n")
updateSelectizeInput( session, "RS", choices = getNamedList2( List_RS_short ), selected=ifelse( is.null(input$RS), "Syndrome grippal", input$RS ) ) #"Syndrome grippal"
} else {
cat( "\ninput$RS:", input$RS, "\n")
updateSelectizeInput( session, "RS", choices = getNamedList2( Liste_RS ), selected=ifelse( is.null(input$RS), "Syndrome grippal", input$RS ) ) #"Syndrome grippal"
}
})
#~~~~~~~~~~~~~~ UI that depend on the language chosen ~~~~~~~~~~~~~~
lang <- read.csv2( "Data/lang.csv", as.is=TRUE, row.names=1, encoding="UTF-8")
# Translates to french and capitalize
toCapfrench <- function( text ){
return( cap( lang[ text, "fr"] ) )
}
# Creation of the vector of reactive values
values <- reactiveValues( language="en" )
onclick( "fr_flag", expr={
values$language <- "en"
#updateSelectizeInput( session, "language", selected="en" )
#info( paste("clicked now", values$language ) )
})
onclick( "en_flag", expr={
values$language <- "fr"
#updateSelectizeInput( session, "language", selected="fr" )
#info( paste("clicked now", values$language ) )
})
# Function that translates text into current language
tr <- function(text){
#return( sapply( text,function(s) lang[s, values$language], USE.NAMES=FALSE ) )
res <- lang[ text, values$language ] #
res[ is.na(res)] <- text[ is.na(res)]
return( res )
}
# Function that returns a named list from a dataset and a chosen language
getNamedList <- function( d ){
l <- as.list( d$key )
names( l ) <- d[ , values$language ]
return( l )
}
# Function that returns a named list from an input list, using the main dictionnary
getNamedList2 <- function( l, d=lang ){
ll <- as.list( l )
names( ll ) <- d[ l, values$language ]
names( ll )[ is.na(names( ll )) ] <- l[ is.na(names( ll )) ]
return( ll )
}
# Function that calculates the day range of a week
# @d: date
getDayRange <- function( d ){
if( values$language == "fr" ){
dayrange <- paste( "du", format( d, format="%d/%m/%Y" ), "au", format( d+6, format="%d/%m/%Y" ) )
} else {
dayrange <- paste( "from", format( d, format="%Y-%m-%d" ), "to", format( d+6, format="%Y-%m-%d" ) )
}
return( dayrange )
}
output$uiSBtitre <- renderUI({
HTML("<img src='img/logo_SPF.png'>",
paste( '<span style="font-family:Trebuchet MS; color: #181866;">',
tr( "titre" ), '</span>', sep="") )
})
output$uiSBlang_message <- renderUI({
HTML(
paste( '<span style="font-size:11px;">', tr( "lang_message" ), '</span>',
ifelse( values$language=="fr",
'<span id="fr_flag" class="menu_links"> <img src="img/en.png"> </span>',
'<span id="en_flag" class="menu_links"> <img src="img/fr.png"> </span>'
),
sep="")
)
})
output$uiSBloading<- renderUI({
HTML( tr( "loading" ), "..." )
})
output$uiSBsyndgroup <- renderUI({
HTML( hh( tr( "syndromic grouping" ) ) )
})
output$uiSBlanguage<- renderUI({
hh( tr( "language" ) )
})
output$uiSBdata_upload<- renderUI({
HTML( tr( "data uploaded on" ), " ", endingtime$date, tr("at"), endingtime$heure, "." )
})
output$uiSBsituation <- renderUI({
HTML( '<i class="fa fa-warning"></i>', tr('situation') )
})
output$uiSBminimapsAlarm <- renderUI({
HTML( '<i class="fa fa-globe"></i>', tr('alarm maps') )
})
output$uiSBminimapsProp <- renderUI({
HTML( '<i class="fa fa-globe"></i>', tr('proportion maps') )
})
output$uiSBalarmList <- renderUI({
HTML( '<i class="fa fa-list-ol"></i>', tr('alarm list') )
})
output$uiSBdata <- renderUI({
HTML( '<i class="fa fa-list"></i>', tr('data') )
})
output$uiSBtimeSeries <- renderUI({
HTML( '<i class="fa fa-bar-chart"></i>', tr('time series') )
})
output$uiSBtable <- renderUI({
HTML( '<i class="fa fa-table"></i>', tr('table') )
})
output$uiSBgauges <- renderUI({
HTML( '<i class="fa fa-tachometer"></i>', tr('gauges') )
})
output$uiSBmaps <- renderUI({
HTML( '<i class="fa fa-globe"></i>', tr('maps') )
})
output$uiSBcalendar <- renderUI({
HTML( '<i class="fa fa-calendar"></i>', tr('calendar') )
})
output$uiSBdetermination <- renderUI({
HTML( '<i class="fa fa-flag"></i>', tr('determination') )
})
output$uiSBthresholds <- renderUI({
HTML( '<i class="fa fa-bell"></i>', tr('thresholds') )
})
output$uiSBserfling <- renderUI({
HTML( '<i class="fa fa-bar-chart"></i>', tr('Serfling') )
})
output$uiSBrobustSerfling <- renderUI({
HTML( '<i class="fa fa-bar-chart"></i>', tr('Serfling_robuste') )
})
output$uiSBHMM <- renderUI({
HTML( '<i class="fa fa-bar-chart"></i>', tr('HMM') )
})
output$uiSBalarmMatrix <- renderUI({
HTML( '<i class="fa fa-table"></i>', tr('alarm matrix') )
})
output$uiSBalarmLevelMap <- renderUI({
HTML( '<i class="fa fa-globe"></i>', tr('alarm level map') )
})
output$uiSBhelp <- renderUI({
HTML( '<i class="fa fa-question-circle"></i>', tr('help') )
})
output$uiSBmethods <- renderUI({
HTML( '<i class="fa fa-book"></i>', tr('methods') )
})
output$uiSBdataResults <- renderUI({
HTML( '<i class="fa fa-info"></i>', tr('results') )
})
output$uiSBdataDesc <- renderUI({
HTML( '<i class="fa fa-book"></i>', tr('data') )
})
output$uiSBdetectionResults <- renderUI({
HTML( '<i class="fa fa-bell"></i>', tr('detection method results') )
})
output$uiSBalarmLevels <- renderUI({
HTML( '<i class="fa fa-exclamation-triangle"></i>', tr('alarm levels') )
})
output$uiSBalarmMatrixInfo <- renderUI({
HTML( '<i class="fa fa-table"></i>', tr('alarm matrix') )
})
output$uiSBwhatisnew <- renderUI({
HTML( '<i class="fa fa-lightbulb-o "></i>', tr("what is new") )
})
output$uiSBlinks <- renderUI({
HTML( '<i class="fa fa-external-link-square"></i>', tr('links') )
})
##### Download buttons #####
### Dectection method results
output$uiSBdownloadmet_title <- renderUI({
HTML( hh( tr( 'download title 1' ) ) )
})
output$uiSBdownloadmet_button <- renderUI({
downloadButton( 'downloadmet', tr( 'download' ) )
})
output$uiSBdownloadmet_legend <- renderUI({
HTML( paste( "<a class='menu_links' id='lien_met'>", tr( "file description" ), "</a>", sep="" ) )
})
### Alarm levels
output$uiSBdownloadlev1_title <- renderUI({
HTML( hh( tr( 'alarm levels' ) ) )
})
output$uiSBdownloadlev1_button <- renderUI({
downloadButton( 'downloadlev1', tr( 'download' ) )
})
output$uiSBdownloadlev1_legend <- renderUI({
HTML( paste( "<a class='menu_links' id='lien_lev1'>", tr( "file description" ), "</a>", sep="" ) )
})
### Alarm matrix
output$uiSBdownloadmat_title <- renderUI({
HTML( hh( tr( 'alarm matrix' ) ) )
})
output$uiSBdownloadmat_button <- renderUI({
downloadButton( 'downloadmat', tr( 'download' ) )
})
output$uiSBdownloadmat_legend <- renderUI({
HTML( paste( "<a class='menu_links' id='lien_mat'>", tr( "file description" ), "</a>", sep="" ) )
})
# Data of the alarm map
output$uiSBdownloadmap_title <- renderUI({
HTML( hh( tr( 'download title 2' ) ) )
})
output$uiSBdownloadmap_button <- renderUI({
downloadButton( 'downloadmap', tr( 'download' ) )
})
output$uiSBdownloadmap_legend <- renderUI({
HTML( paste( "<a class='menu_links' id='lien_map'>", tr( "file description" ), "</a>", sep="" ) )
})
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
##################################################
# FILTRES
##################################################
# Ensemble du jeu de données pour le pas de temps selectionné
Dataset <- reactive({
#tt <- ifelse( !is.null(input$TimeUnit), input$TimeUnit, "week" )
get( paste("Data_", input$TimeUnit, sep="") )
})
# On crée deux valeurs réactive qui vont prendre l'index de la région selectionnée et
# la liste des sources selectionnées.
observe({
values$Region <- ifelse( input$Geo %in% c("FRANCE", "METROPOLE"), input$Geo, ifelse(input$Geo=="regionsA", input$RegionA, input$RegionN) )
if( is.null(input$Source) || input$Source== "Toutes" ){
values$Source <- unique( Dataset()[ Classe_age==input$Age & RS==input$RS & Region==values$Region, Source ] )
} else {
values$Source <- input$Source
}
})
# Sous-ensemble du jeu de données : sélection sur "RS" "Region" "Source" "Classe_age"
Datasubset <- reactive({
dd <- Dataset()[ .(input$RS, values$Region, values$Source, input$Age) ]
d1 <- switch( input$TimeUnit,
"day"=input$DateStart,
"week"=input$DateStart-6,
"month"=as.Date( paste(format( input$DateStart, "%Y-%m" ), "01", sep="-") )
)
dd <- dd[ d>=d1 & d<=input$DateEnd ]
return(dd)
})
output$Source = renderUI({
vars <- c( "Toutes", unique( Dataset()[ Classe_age==input$Age & RS==input$RS & Region==values$Region, Source ] ) )
selectInput( "Source",
HTML('<b><span style="color: #181866"><font>Source</font></span></b>'),
choices = getNamedList2( vars ),
selected = input$Source )
})
output$Age = renderUI({
vars <- levels( Dataset()[ .(input$RS, values$Region) ]$Classe_age )
if( !is.null(input$Source) && input$Source=="Sentinelles" ){
vars <- "Tous ages"
}
# For menu determnination of epidemic periods
if( input$menu=="determination" ) {
if( input$RS == "Bronchiolite" ){
vars <- c( "Tous ages", "Moins de 2 ans")
} else {
vars <- "Tous ages"
}
}
selectInput( "Age",
hh( tr("age class") ),
choices = getNamedList2( vars ),
selected = input$Age
)
})
output$Geo = renderUI ({
radioButtons("Geo",
hh( tr("analyzed zone") ),
#choices=getNamedList( lang_analyzedzones )
choices=getNamedList2( List_analyzed_zones ),
selected=input$Geo
)
})
output$GeoMap = renderUI ({
radioButtons("GeoMap",
hh( tr("cartography") ),
#getNamedList( lang_mappedzones )
getNamedList2( List_mapped_zones ),
selected=input$GeoMap
)
})
output$label_TimeUnit <- renderText( {
hh( tr("time unit") )
})
output$label_newRegion <- renderText( {
hh( tr("new region") )
})
output$label_oldRegion <- renderText( {
hh( tr("old region") )
})
output$label_DateStart <- renderText( {
hh( paste( tr( paste( "starting", input$TimeUnit, sep=" " ) ) ) )
} )
output$label_DateEnd <- renderText( {
lab <- ifelse( (input$menu=='donnees' & input$menu_donnees=='cartes')
| ( input$menu=='determination' & (input$menu_determination=='carte_alarme' | input$menu_determination=='matrice_alarme') )
| ( input$menu=='situation' & (input$menu_situation=='minimap_proportion' | input$menu_situation=='minimap_alarme') )
, cap( tr( input$TimeUnit ) ),
paste( tr( paste( "ending", input$TimeUnit, sep=" " ) ) )
)
hh( lab )
} )
output$uiSBDateStart <- renderUI({
dateInput( 'DateStart',
label= htmlOutput("label_DateStart"),
value = dayrange$first,
min = dayrange$first, max = dayrange$last,
format = tr( "dateInput format"), startview = "month", weekstart = 1,
language = tr( "language" ) )
})
output$uiSBDateEnd <- renderUI({
dateInput( 'DateEnd', label= htmlOutput("label_DateEnd"),
value = lastsunday,
min = dayrange$first, max = dayrange$last,
format = tr( "dateInput format"), startview = "month", weekstart = 1,
language = tr( "language" )
)
})
##################################################
#SITUATION EPIDEMIOLOGIQUE
##################################################
#################################################
# MINI ALARM MAPS
#################################################
# NB: separating bronchiolitis All ages and Younger than 2 years
for( i in 1:length(List_RS_short) ) {
# Local permet de faire la boucle en faisant avancer i (sinon ne marche pas)
local({
# Syndromic grouping
rs <- List_RS_short[i]
# Label of the map : name of the syndromic grouping in the chosen language
namelab <- paste( "label_alarm_map", i, sep="_" )
output[[ namelab ]] <- renderText({ tr( rs ) })
# Classes d'age disponibles pour ce jeu de données au pas de temps selectionné
list_ages <- unique( alarm_level[ RS==rs ]$Classe_age )
for( j in 1:length( list_ages ) ){
local({
age <- list_ages[ j ]
# id de l'element HTML contenant la petite carte à cliquer
id <- ifelse( length(list_ages)>1, paste( "petite_carte_alarme", i, j, sep="_"), paste( "petite_carte_alarme", i, sep="_"))
onclick( id, expr=
{ updateSelectizeInput(session, "RS", selected = rs );
updateSelectizeInput(session, "Age", selected = age );
updateTabsetPanel(session, inputId="menu", selected = "determination");
updateTabsetPanel(session, inputId="menu_determination", selected = "carte_alarme")
}
)
# Nom du graphique pour le regroupement syndromique
nom <- ifelse( length(list_ages)>1, paste( "mapAlarme", i, j, sep="_"), paste( "mapAlarme", i, sep="_") )
output[[ nom ]] <- renderPlot( {
# Selection du type de region
if( is.null(input$GeoMap) || input$GeoMap=="regionsN" ) {
map.fr <- map.fr_regionsN
liste_reg <- Liste_regionsN
corresp_nomreg_numreg <- corresp_nom_num_regionsN
} else {
map.fr <- map.fr_regionsA
liste_reg <- Liste_regionsA
corresp_nomreg_numreg <- corresp_nom_num_regionsA
}
# Selection de la date de la carte : dernier temps en cours
DateEnd <- ifelse( is.null(input$DateEnd), max( alarm_level$d ), input$DateEnd )
lastd <- max( alarm_level$d[ alarm_level$d <= DateEnd ] )
#print( nom ); print( age )
tmp <- alarm_level[ CJ( rs, liste_reg, as.character(age), lastd ), nomatch=0L ][ corresp_nomreg_numreg, on=c(Region="code_reg") ]
tmp[, col := coul.alarme[ tmp$niv_alarme ] ]
##### Carte
par( mar=c(0,0,0,0) )
plot( map.fr, col=tmp$col )
#box("figure", bty="o")
}, width=150, height=170*0.75)
})
}
})
}
output$label_allage_alarm <- renderText( {
tr("Tous ages")
})
output$label_younger2_alarm <- renderText( {
tr("Moins de 2 ans")
})
#################################################
# MINI PROPORTION MAPS
#################################################
output$HeaderTableAccueil <- renderText( {
switch( length(unique( Dataset()$Source )),
"An error has occured in header names",
"<TABLE width=100% class='HeaderCartes' ><TR>
<TH width='50%'>SAU</TH>
<TH>SOS</TH></TR>
</TABLE>",
"<TABLE width=100% class='HeaderCartes' ><TR>
<TH width='33.33%'>SAU</TH>
<TH width='33.33%'>SOS</TH>
<TH>Sentinelles</TH></TR>
</TABLE>"
)
})
# Time (day, week or month) of the mapped data
output$time_prop_maps <- renderText( {
tt <- which.max( Dataset()$d[Dataset()$d<=input$DateEnd ] )
temps <- paste( cap( tr(input$TimeUnit) ),
as.character( Dataset()[ tt, toCapfrench( input$TimeUnit ), with=F] )
)
if( input$TimeUnit=="week" ){
#temps <- paste( temps, Dataset()$Dates[ tt ], sep="<BR>")
temps <- paste( temps, getDayRange( Dataset()$d[ tt ] ), sep="<BR>")
}
temps
})
output$time_alarm_maps <- renderText( {
tt <- which.max( Dataset()$d[Dataset()$d<=input$DateEnd ] )
temps <- paste( cap(tr(input$TimeUnit)),
as.character( Dataset()[ tt, toCapfrench(input$TimeUnit), with=F] )
)
if( input$TimeUnit=="week" ){
#temps <- paste( temps, Dataset()$Dates[ tt ], sep="<BR>")
temps <- paste( temps, getDayRange( Dataset()$d[ tt ] ), sep="<BR>")
}
temps
})
# Petites cartes pour l'onglet situation epidémiologique
# Choix de la source et du RS
for( i in 1:length(List_RS_short) ) {
# Local permet de faire la boucle en faisant avancer i (sinon ne marche pas)
local({
# Syndromic grouping
rs <- List_RS_short[i]
# Label of the map : name of the syndromic grouping in the chosen language
namelab <- paste( "label_prop_map", i, sep="_" )
output[[ namelab ]] <- renderText({ tr( rs ) })
onclick( paste("petite_carte", i, sep="_"), expr=
{ updateSelectizeInput(session, "RS", selected = rs );
updateTabsetPanel(session, inputId="menu", selected = "donnees");
updateTabsetPanel(session, inputId="menu_donnees", selected = "cartes")
}
)
# Nom du graphique pour le regroupement syndromique (contient toutes les sources)
nom <- paste( "mapAccueil", i, sep="_")
par( mfrow=c(1,1), mar=c(0,0,0,0) )
widthMap <- reactive( { 150*length(unique( Dataset()[ RS==rs ]$Source ))} )
output[[nom]] <- renderPlot( {
cat( "\nPetite carte", nom, "\n")
# Selection du type de region
if( is.null(input$GeoMap) || input$GeoMap=="regionsN" ) {
map.fr <- map.fr_regionsN
liste_reg <- Liste_regionsN
corresp_nomreg_numreg <- corresp_nom_num_regionsN
} else {
map.fr <- map.fr_regionsA
liste_reg <- Liste_regionsA
corresp_nomreg_numreg <- corresp_nom_num_regionsA
}
# Selection de la date de la carte : dernier temps en cours
lastd <- max( Dataset()$d[ Dataset()$d <= input$DateEnd ] )
print( lastd )
# Sources disponibles pour ce jeu de données au pas de temps selectionné
list_sources <- unique( Dataset()[ RS==rs ]$Source )
#print( list_sources )
par( mfrow=c(1, length(list_sources)), mar=c(0,0,0,0) )
for( so in list_sources ){
# Selection du regroupement syndromique, des regions, de la source, de la classe d'âge et de la date
# Merge du subset avec les numeros de region
# Ordonne selon le numero des regionsen mergeant sur corresp_nomreg_numreg
tmp <- Dataset()[ CJ( rs, liste_reg, so, "Tous ages", lastd ), nomatch=0L ][ corresp_nomreg_numreg, on=c(Region="code_reg") ]
# rs="Syndrome grippal"
#lastd <- max( alarm_level$d[ alarm_level$d <= input$DateEnd ] )
#tmp <- alarm_level[ CJ( rs, liste_reg, "Tous ages", lastd ), nomatch=0L ][ corresp_nomreg_numreg, on=c(Region="code_reg") ]
#tmp[, col := coul.alarme[ tmp$niv_alarme ] ]
###### Creation de 4 niveaux de Proportion2
seuils <- seuils_carte$seuil_Proportion2[ seuils_carte$Source==so
& seuils_carte$Classe_age=="Tous ages"
& seuils_carte$RS==rs ]
maxi <- max( ceiling(tmp$Proportion2), max(seuils)+1, na.rm=T )
lev <- unique( c(0, seuils[seuils < maxi], maxi ) )
cat( "\n", rs, so, "niveau:", lev, "\n" )
tmp[, classe.prop := cut( tmp$Proportion2, breaks=lev, right=F, include.lowest=T ) ]
tmp[, col := coul.prop[ tmp$classe.prop ] ]
tmp[ tmp$Nb_total_passages==0, col:=NA ]
##### Carte
plot( map.fr, col=tmp$col )
#box(bty="o")
}
}, width=widthMap, height=170*0.75)
})
}
#################################################
# ALARM LIST
#################################################
#output$TitreListing<- renderText( paste( tr("alarm list"), ", ", getname.region( unique(Datasubset()$Region)), sep="" ) )
output$ListingAlarmes <- DT::renderDataTable({
dd <- alarm_list[ Region==values$Region & d>= input$DateStart-6 & d<=input$DateEnd ]
if( !is.null(dd) ){
setorder( dd, -d )
# translate the syndromic groupings
dd[ , RS:=tr( as.character(RS) ) ]
# translate the age classes
dd[ , Classe_age:=tr( as.character(Classe_age) ) ]
# translate the methods
dd[ , Methode:=gsub( "Serfling robuste", tr("rob serf"), Methode, fixed=T) ]
dd[ , Methode:=gsub( "Serfling", tr("serf"), Methode, fixed=T) ]
# translate the week dates
if( values$language=="en" ){
dd[, Dates:=paste( "from", d, "to", d+7 ) ]
}
dd[ , c("d", "Region"):=NULL ]
nomscols_aff <- tr( names(dd) )
}
DT::datatable( if (is.null( dd )) invisible()
else dd,
rownames = FALSE,
colnames = nomscols_aff,
extensions = c("Buttons"),
options=list(
lengthMenu = list(c(10, 25, 50, -1), c('10', '25','50', 'All')),
pageLength = 10,
orderClasses = TRUE,
dom = 'Blfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
)
, caption=paste( tr("alarm list"), ", ", getname.region( unique(Datasubset()$Region)), sep="" )
)
})
output$FootnoteAlarmList <- renderText({
paste0( tr("serf"), ": ", tr("Serfling"),
"<BR>HMM: ", tr("HMM")
)
})
#####################################################################
# SERIE TEMPORELLE REPRESENTANT LA PROPORTION ET/OU TAUX D'INCIDENCE
#####################################################################
output$dygraph_series <- renderDygraph({
dd <- dcast.data.table( Datasubset()[, .(Proportion2, Source, d) ],d ~ Source, value.var="Proportion2" )
d3 <- xts( dd[ , names(dd)!="d", with=F ], order.by=dd[, d])
dy <- dygraph( d3, main=paste( tr( input$RS ), tr( input$Age ),
tr( getname.region( unique(Datasubset()$Region)) ),
sep=" - ")
)
if( ncol(d3) == 1){
dy <- dy %>%
dyAxis( 'y', label=names(d3) )
} else {
dy <- dy %>%
dyAxis( 'y', label=ifelse( ncol(d3)>2, paste( names(d3)[-ncol(d3)], collapse=", " ), names(d3)[1] ) ) %>%
dyAxis( 'y2', label=names(d3)[ncol(d3)] ) %>%
dySeries( names(dd)[ ncol(dd)], axis = 'y2' )
}
dy %>% dyLegend(width = 500)
})
##################################################
# DATA TABLE
##################################################
#output$TitreDT <- renderText( paste( tr(input$RS), tr(input$Age), tr( getname.region( unique(Datasubset()$Region)) ), sep=" - " ) )
output$DataTable <- DT::renderDataTable({
nomscols <- names( Datasubset() )
nomscols <- nomscols[ ( nomscols %in% c( "Semaine", "Dates", "Mois", "Jour", "Source",
"Nb_passages", "Nb_total_passages", "Proportion2",
"Proportion_low", "Proportion_up") ) ]
nomscols_aff <- tr( nomscols ) # Pour l'affichage
#nomscols_aff[ nomscols_aff=="Nb_passages"] <- 'Nombre de passages'
#nomscols_aff[ nomscols_aff=="Nb_total_passages"] <- 'Nombre total de passages'
if( !is.null(Datasubset()) ){
tmp <- Datasubset()[ , c("d", nomscols), with = FALSE ]
if( values$language=="en" ){
tmp[, Dates:=paste( "from", d, "to", d+7 ) ]
}
setorder( tmp, -d )
tmp[ , d:=NULL ]
tmp[ , Proportion2:=round(Proportion2) ]
}
# On réordonne Datasubset() par temps décroissant : observations les plus récentes en premier
DT::datatable( if (is.null( Datasubset() )) invisible()
else tmp,
rownames = FALSE,
colnames = nomscols_aff,
extensions = c("Buttons"),
options=list(
pageLength = 10,
lengthMenu = list(c(10, 25, 50, -1), c('10', '25','50', 'All')),
orderClasses = TRUE,
dom = 'Blfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')