This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
forked from Public-Health-Scotland/DRHS_Data_Explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
3378 lines (2886 loc) · 127 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
#Name: Drug Related Hospital Statistics (DRHS) Data explorer page
#Author: Mike Smith
#Created: 24/01/2019
#Type: Data visualisation
#Written on: RStudio
#Written for: R version 3.5.1
#Output: Shiny application
#This is the full version of the data explorer for the new DRHS dashboard.
#Currently there are tabs for
# Tab 1) A Home Page
# Tab 2) Time Trend (Geography)
# Tab 3) Time Trend (Substances)
# Tab 4) Age/Sex
# Tab 5) Deprivation
# Tab 6) Table
#libraries
library(shiny)
library(dplyr)
library(plotly)
library(shinyWidgets)
library(stringr)
library(DT)
library(forcats)
library(shinyBS)
library(bsplus)
##############################################.
############## Reading In Data ----
##############################################.
#Data to be used for explorer and trend pages
#Following is rounded data
all_data<- readRDS("s06-temp09_num_rate_perc_R-SHINY_rounded.RDS")
#need to rename the final column as value
all_data<-all_data %>%
rename("value" = value_Round)
#Round to two decimal places.
all_data<-all_data%>%
mutate(value = round(value, 2))
#We will manually change the names of factors in R until we have an agreed
#terminology for the hospital type and clinical type, as well age and sex.
all_data<-all_data %>%
mutate(hospital_type= fct_recode(hospital_type,
"General acute"= "General acute (SMR01)",
"Psychiatric" ="Psychiatric (SMR04)",
"Combined gen acute/psych" = "Combined (General acute/Psychiatric)"),
clinical_type= fct_recode(clinical_type,
"Mental & behavioural (M&B)" = "Mental and Behavioural",
"Overdose (OD)" = "Overdose",
"Combined M&B/OD" = "Combined (Mental and Behavioural/Overdose)"),
drug_type = fct_recode(drug_type, "Any drug type" = "All"),
age_group = fct_recode(age_group, "All age groups" = "All"),
sex = fct_recode(sex, "Both sexes" = "All"))
#Data that is not visualized
length_of_stay <- readRDS("s07-temp08_lsty_R-SHINY_rounded.RDS")
length_of_stay<-length_of_stay %>%
rename("perc_less_1week" = perc_less_1week_round,
"perc_more_1week" = perc_more_1week_round,
"total" = total_rounded)
emergency_admissions<- readRDS("s08-temp08_emerAdm_R-SHINY_rounded.RDS")
emergency_admissions <-emergency_admissions %>%
rename("perc_adm_emer" = perc_adm_emer_round,
"perc_adm_other" = perc_adm_other_round,
"total" = total_rounded)
drug_type_by_hospital<-readRDS ("s09-temp05_dist_hospit_R-SHINY_rounded.RDS")
drug_type_by_hospital<-drug_type_by_hospital %>%
rename("total" = total_rounded)
#filter data set for data for each tab
time_trend <- all_data %>%
filter(age_group == "All age groups",
sex == "Both sexes",
simd == "All") %>%
select(-c(age_group,sex,simd))
age_sex <- all_data %>%
filter(geography =="Scotland",
simd== "All"
) %>%
select(-c(simd, geography_type,geography))
deprivation <- all_data %>%
filter(geography =="Scotland",
simd != "All") %>%
select(-c(age_group,sex, geography_type,geography))
#We then create the options for users to choose from in the drop down menus.
#Drug Types are created as list to allow different options dependent on the
#Hospital admission types
hospital_types <- as.character(unique(all_data$hospital_type))
hospital_types<-c(hospital_types[3],hospital_types[1],hospital_types[2])
clinical_types <- as.character(unique(all_data$clinical_type))
clinical_types<-c(clinical_types[3],clinical_types[1],clinical_types[2])
activity_type <- as.character(unique(all_data$activity_type))
location_types <- as.character(unique(all_data$geography_type))
locations<- as.character(unique(all_data$geography))
geography_list<-list("Scotland" = locations[1:3],
"NHS Board of residence" = locations[4:17],
"ADP of residence" = locations[18:48])
drug_types<- as.character(unique(all_data$drug_type))
drug_types1<- list("Main Categories" = as.character(unique(all_data$drug_type)[1:7]),
"Opioids Sub Categories" = as.character(unique(all_data$drug_type)[8:10]))
drug_types2<- as.character(unique(all_data$drug_type)[1:7])
measures<- as.character(unique(all_data$measure))
#Add in age, sex, SIMD and financial years options for demographic tabs
age <- as.character(unique(all_data$age_group))
sex <- as.character(unique(all_data$sex))
financial_years <- as.character(unique(all_data$year))
SIMD<- as.character(unique(all_data$simd))
#we need to look at altering the data for the tornado chart so that male values
#negative to allow it to work
#Convert males to negative (and remove all)
age_sex_male <- age_sex %>%
filter(sex == "Male"
& age_group != "All age groups") %>%
mutate(value = value * -1)
#Then remove females
age_sex_female <- age_sex %>%
filter(sex == "Female"
& age_group != "All age groups")
#recombine them into one chart
age_sex_tornado <- rbind(age_sex_male, age_sex_female)
#we can now set up the data for that from the data trend page
activity_summary<-all_data %>%
filter(drug_type == "Any drug type",
age_group == "All age groups",
sex == "Both sexes",
simd == "All",
measure == "Rate")
drug_summary<- all_data %>%
filter(activity_type == "Stays",
drug_type %in% drug_types2,
drug_type != "Any drug type",
age_group == "All age groups",
sex == "Both sexes",
simd == "All",
measure == "Rate")
demographic_summary<- all_data %>%
filter(drug_type == "Any drug type",
activity_type =="Patients",
((age_group != "All age groups" & sex == "Both sexes" & simd =="All")|
(age_group == "All age groups" & sex != "Both sexes" & simd =="All")|
(age_group == "All age groups" & sex == "Both sexes" & simd !="All")),
measure == "Rate")
#Keep only those columns that are necessary
activity_summary<-activity_summary %>%
select(year,hospital_type,clinical_type,activity_type,
geography_type,geography,value)
drug_summary<-drug_summary %>%
select(year,hospital_type,clinical_type,drug_type,
geography_type,geography,value)
demographic_summary<-demographic_summary %>%
select(year,hospital_type,clinical_type,
geography_type,geography,
age_group,sex,simd,
value)
#We can then drop unnecessary columns from these tables
length_of_stay <- length_of_stay %>%
select(-activity_type)%>%
mutate(perc_less_1week = round(perc_less_1week, 2),
perc_more_1week = round(perc_more_1week, 2),
hospital_type= fct_recode(hospital_type,
"General acute"= "General acute (SMR01)",
"Psychiatric" ="Psychiatric (SMR04)",
"Combined gen acute/psych" = "Combined (General acute/Psychiatric)"),
clinical_type= fct_recode(clinical_type,
"Mental & behavioural (M&B)" = "Mental and Behavioural",
"Overdose (OD)" = "Overdose",
"Combined M&B/OD" = "Combined (Mental and Behavioural/Overdose)"),
drug_type = fct_recode (drug_type,
"Sedatives/ Hypnotics" = "Sedatives/Hypnotics",
"Any drug type" = "All"),
age_group = fct_recode(age_group, "All age groups" = "All"),
sex = fct_recode(sex, "Both sexes" = "All"))
emergency_admissions <- emergency_admissions %>%
select(-activity_type)%>%
mutate(perc_adm_emer = round(perc_adm_emer, 2),
perc_adm_other = round(perc_adm_other, 2),
hospital_type= fct_recode(hospital_type,
"General acute"= "General acute (SMR01)",
"Psychiatric" ="Psychiatric (SMR04)",
"Combined gen acute/psych" = "Combined (General acute/Psychiatric)"),
clinical_type= fct_recode(clinical_type,
"Mental & behavioural (M&B)" = "Mental and Behavioural",
"Overdose (OD)" = "Overdose",
"Combined M&B/OD" = "Combined (Mental and Behavioural/Overdose)"),
drug_type = fct_recode (drug_type,
"Sedatives/ Hypnotics" = "Sedatives/Hypnotics",
"Any drug type" = "All"),
age_group = fct_recode(age_group, "All age groups" = "All"),
sex = fct_recode(sex, "Both sexes" = "All"))
drug_type_by_hospital <- drug_type_by_hospital %>%
select(-c(geography_type,geography,
age_group,sex,simd))%>%
mutate(perc_source01 = round(perc_source01, 2),
perc_source04 = round(perc_source04, 2),
perc_sourceBOTH = round(perc_sourceBOTH, 2),
hospital_type= fct_recode(hospital_type,
"Combined gen acute/psych" = "Combined (General acute/Psychiatric)"),
clinical_type= fct_recode(clinical_type,
"Mental & behavioural (M&B)" = "Mental and Behavioural",
"Overdose (OD)" = "Overdose",
"Combined M&B/OD" = "Combined (Mental and Behavioural/Overdose)"),
drug_type = fct_recode (drug_type,
"Sedatives/ Hypnotics" = "Sedatives/Hypnotics",
"Any drug type" = "All"))
##############################################.
############## User Interface ----
##############################################.
{
#Beginning of UI
ui <- fluidPage(
style = "width: 100%; height: 100%; max-width: 1200px;",
tags$head(
tags$style(
type = "text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"
),
#The following chunk of code does two things:
# 1. Paints the ribbon that contains the tab headers white.
# 2. Highlights the header of the active tab in blue.
tags$style(
HTML("
.tabbable > .nav > li > a {color: #000000;}
.tabbable > .nav > li[class = active] > a {background-color: #0072B2;color: #FFFFFF;}
")
)
),
#We will add in a title panel title as well as ISD logo.
titlePanel(title=div(img(src="ISD_NSS_logos.png",height = 96,
width = 223,
style = "float:right;"),
h1("Drug-Related Hospital Statistics"),
h4("Drug and Alcohol Misuse"),
style = "height:96px;"),
windowTitle = "Drug-Related Hospital Statistics"),
#We are going to divide our UI into discrete sections, called tab panels.
#To do this, we need the layout "tabsetPanel()".
tabsetPanel(
id = "Panels",
##############################################.
############## Home tab ----
##############################################.
#We begin with an introduction tab, where we introduce the explorer and...
#its purpose.
#
tabPanel(
"Introduction",
icon = icon("info-circle"),
style = "float: top; height: 95%; width: 95%;
background-color: #FFFFFF; border: 0px solid #FFFFFF;",
column(2,
h3("Data explorer")
),
column(
8,
p(
br(),
"The Data explorer provides a detailed breakdown of Drug-Related
Hospital Statistics data in Scotland over time. You can visualise these
data using the following pages:"
),
tags$ul(
tags$li(
tags$b(actionLink(
"link_to_geography", "Time trend (location comparison)"
)),
icon("line-chart"),
" - compare data by location, over time."
),
tags$li(
tags$b(actionLink(
"link_to_substances", "Time trend (drug type comparison)"
)),
icon("line-chart"),
" - compare data by drug type, over time."
),
tags$li(
tags$b(actionLink(
"link_to_age_sex", "Age/sex"
)),
icon("child"),
" - show data by age group and sex."
),
tags$li(
tags$b(actionLink(
"link_to_deprivation", "Deprivation"
)),
icon("bar-chart"),
" - show data by deprivation quintile."
),
tags$li(
tags$b(actionLink(
"link_to_table", "Table"
)),
icon("table"),
" - view and customise data tables."
)
),
p(
"Click the button below to download the glossary."
),
p("A less detailed overview of drug-related hospital stays in Scotland
over time is available in the",
tags$a(
href = "https://scotland.shinyapps.io/nhs-drhs-trend-data/",
"Trend data"
),
" page"),
bs_accordion(id = "drhs_introduction_text") %>%
bs_set_opts(panel_type = "primary") %>%
bs_append(title = "Technical information",
content =
tags$ul(
tags$li(
"The Data explorer visualises information recorded in the SMR01 and SMR04
datasets. The SMR01 dataset records general acute hospital inpatient and day
case activity and SMR04 records psychiatric hospital inpatient and day case
activity."
),
tags$li(
"Information is generally available for financial years 1996/97 to 2017/18.
Where shown, ADP information is available from 1997/98 and new patient trends
are available from 2006/07."
),
tags$li(
"Data completeness may vary slightly from year to year. As a result,
data are provisional and subject to change. For more information, visit
the ",
tags$a(
href = "http://www.isdscotland.org/products-and-Services/Data-Support-and-Monitoring/SMR-Completeness/",
"SMR completeness"
),
" webpage."
),
tags$li(
"Diagnostic information is recorded using the International Statistical
Classification of Diseases and Related Health Problems, 10th Edition
(ICD-10). ICD-10 codes used to classify drug-related hospital stays
are listed in Appendix 1 (see Analytical definitions) in the ",
HTML(paste0('<a href="https://www.isdscotland.org/Health-Topics/Drugs-and-Alcohol-Misuse/Publications/2019-05-28/2019-05-28-DRHS-Report.pdf">full report</a>.')),"
Note that patients may have more than one
drug-related diagnosis per stay."
),
tags$li(
"Statistical disclosure control has been applied to protect patient
confidentiality. Therefore, the figures presented in this dashboard may
not be additive and may differ from previous publications.
For more information, please refer to the ",
HTML(paste0('<a href="http://www.isdscotland.org/About-ISD/Confidentiality/disclosure_protocol_v3.pdf">NSS Statistical Disclosure Control Protocol</a>.'))
),
tags$li(
"Further technical details can be seen on the ",
tags$a(href = "https://www.isdscotland.org/Health-Topics/Drugs-and-Alcohol-Misuse/Publications/2019-05-28/data-overview.asp","Data overview"),
" webpage."
)
)
),
downloadButton(outputId = "download_glossary1",
label = "Download glossary",
class = "glossary"),
tags$head(
tags$style(".glossary { background-color: #0072B2; }
.glossary { color: #FFFFFF; }")
),
p(
br(),
"If you experience any problems using this dashboard or have further
questions relating to the data, please contact us at:",
HTML(paste0('<b> <a href="mailto:NSS.isdsubstancemisuse@nhs.net">NSS.isdsubstancemisuse@nhs.net</a></b>.'))
)
#End of column 8 part
)
#End of tab panel
),
##############################################.
############## Geography tab ----
##############################################.
#Create a tab for geography data.
#Insert the description a
tabPanel(
"Time trend (location comparison)",
icon = icon("line-chart"),
style = "height: 95%; width: 95%; background-color: #FFFFFF;
border: 0px solid #FFFFFF;",
h3("Time trend (location comparison)"),
p(
h4(
"Visualise drug-related hospital activity over time and make
comparisons between locations. ")
),
bs_accordion(id = "drhs_location_comparison_text") %>%
bs_set_opts(panel_type = "primary") %>%
bs_append(title = "Data selection",
content = p(
"The chart can be modified using the drop down boxes:",
tags$ul(
tags$li("Hospital type: general acute or psychiatric
hospital data (or a combination);"),
tags$li("Clinical type: mental & behavioural stays,
accidental poisoning/overdose stays (or a combination);"),
tags$li("Activity type: stays, patients or new patients;"),
tags$li("Location: data from Scotland, specific NHS
Boards or Alcohol and Drug Partnerships
(choose up to 8 locations);"),
tags$li("Drug type: the type of drug associated with the
stay (opioid sub categories are available if overdoses
are selected as Clinical type); and,"),
tags$li("Measure: numbers, rates or percentages.")
),
"To download your data selection as a CSV file, use the
'Download data' button under the filters.",
br(),br(),
"For technical information, please see the Introduction page."
))%>%
bs_append(title = "Chart functions",
content = p("At the top-right corner of the
chart, you will see a toolbar with four buttons:",
tags$ul(
tags$li(
icon("camera"),
tags$b("Download plot as a png"),
" - save an image of the chart (not available in Internet Explorer)."
),
tags$li(
icon("search"),
tags$b("Zoom"),
" - click and drag within the chart area to focus on a specific part."
),
tags$li(
icon("move", lib = "glyphicon"),
tags$b("Pan"),
" - click and move the mouse in any direction to modify the chart axes."
),
tags$li(
icon("home"),
tags$b("Reset axes"),
" - click this button to return the axes to their default range."
)
),"Categories can be shown/hidden by clicking on labels in the
legend to the right of the chart."
)
)%>%
bs_append(title = "Table functions",
content = p(HTML("To view
your data selection in a table, use the <a href = '#geography_link'>
'Show/hide table' </a> button at the
bottom of the page."),
tags$ul(
tags$li(tags$b("Show entries"), " - change the number of rows shown
in the table using the drop-down box."),
tags$li(tags$b("Search"), " - enter text to search data for a specific word or
numerical value."),
tags$li(icon("sort", lib = "glyphicon"),
tags$b("Sort"), " - click to sort the table in ascending or
descending order based on the values in a column."),
tags$li(tags$b("Page controls"), " - switch to specific page of data
within the table.")
)
)),
p(
tags$b(
"Note: Statistical disclosure control has been applied to protect
patient confidentiality. Therefore, the figures presented here
may not be additive and may differ from previous publications."
)
),
downloadButton(outputId = "download_glossary2",
label = "Download glossary",
class = "glossary"),
tags$head(
tags$style(".glossary { background-color: #0072B2; }
.glossary { color: #FFFFFF; }")
),
p(""),
wellPanel(
tags$style(
".well { background-color: #FFFFFF;
border: 0px solid #336699; }"
),
#Insert the reactive filters.
#We have SIX filters at this point
# 1 - Hospital/Clinical type
# 2 - Activity Type
# 3 - Geography Type
# 4 - Geography (Multiple)
# 5 - Substance
# 6 - Measure
column(
4,
shinyWidgets::pickerInput(
inputId = "Hospital_Type",
label = "Hospital type",
choices = hospital_types
),
shinyWidgets::pickerInput(
inputId = "Location",
label = "Location (multiple selection)",
choices = geography_list,
multiple = TRUE,
selected = "Scotland",
options = list(size=10,
`live-search`=TRUE,
`selected-text-format` = "count > 1",
`count-selected-text` = "{0} locations chosen (8 Max)",
"max-options" = 8,
"max-options-text" = "Only 8 options can be chosen")
),
downloadButton(outputId = "download_geography",
label = "Download data",
class = "geographybutton"),
tags$head(
tags$style(".geographybutton { background-color:
#0072B2; }
.geographybutton { color: #FFFFFF; }")
)
),
column(
4,
uiOutput("time_trend_clinical_type"),
uiOutput("time_trend_substance1")
),
column(
4,
shinyWidgets::pickerInput(
inputId = "Activity_Type",
label = "Activity type",
choices = activity_type
),
shinyWidgets::pickerInput(
inputId = "Measure",
label = "Measure",
choices = measures,
selected = "Rate"
)
)
),
#In the main panel of the tab, insert the geography plot
mainPanel(
width = 12,
plotlyOutput("geography_plot",
width = "1090px",
height = "500px"),
br(),
HTML("<button data-toggle = 'collapse' href = '#geography'
class = 'btn btn-primary' id = 'geography_link'>
<strong> Show/hide table </strong></button>"),
HTML("<div id = 'geography' class = 'collapse'>"),
br(),
dataTableOutput("geography_table"),
HTML("</div>"),
br(),
br()
)
#End of tab panel
),
##############################################.
############## Substances tab ----
##############################################.
tabPanel(
"Time trend (drug type comparison)",
icon = icon("line-chart"),
style = "height: 95%; width: 95%; background-color: #FFFFFF;
border: 0px solid #FFFFFF;",
h3("Time trend (drug type comparison)"),
p(
h4(
"Visualise drug-related hospital activity over time and make
comparisons between different drug types. "
)),
bs_accordion(id = "drhs_drugs_comparison_text") %>%
bs_set_opts(panel_type = "primary") %>%
bs_append(title = "Data selection",
content = p(
"The chart can be modified using the drop down boxes:",
tags$ul(
tags$li("Hospital type: general acute or psychiatric
hospital data (or a combination);"),
tags$li("Clinical type: mental & behavioural stays,
accidental poisoning/overdose stays (or a combination);"),
tags$li("Activity type: stays, patients or new patients; "),
tags$li("Location: data from Scotland, specific NHS
Boards or Alcohol and Drug Partnerships;"),
tags$li("Drug type: the type of drug associated with the
stay (multiple selection) (opioid sub categories are available if overdoses
are selected as Clinical type); and,"),
tags$li("Measure: numbers, rates or percentages.")
),
"To download your data selection as a CSV file, use the
'Download data' button under the filters.",
br(),br(),
"For technical information, please see the Introduction page."
))%>%
bs_append(title = "Chart functions",
content = p("At the top-right corner of the
chart, you will see a toolbar with four buttons:",
tags$ul(
tags$li(
icon("camera"),
tags$b("Download plot as a png"),
" - save an image of the chart (not available in Internet Explorer)."
),
tags$li(
icon("search"),
tags$b("Zoom"),
" - click and drag within the chart area to focus on a specific part."
),
tags$li(
icon("move", lib = "glyphicon"),
tags$b("Pan"),
" - click and move the mouse in any direction to modify the chart axes."
),
tags$li(
icon("home"),
tags$b("Reset axes"),
" - click this button to return the axes to their default range."
)
),"Categories can be shown/hidden by clicking on labels in the
legend to the right of the chart."
)
)%>%
bs_append(title = "Table functions",
content = p(HTML("To view
your data selection in a table, use the <a href = '#substances_link'>
'Show/hide table' </a> button at the
bottom of the page."),
tags$ul(
tags$li(tags$b("Show entries"), " - change the number of rows shown
in the table using the drop-down box."),
tags$li(tags$b("Search"), " - enter text to search data for a specific word or
numerical value."),
tags$li(icon("sort", lib = "glyphicon"),
tags$b("Sort"), " - click to sort the table in ascending or
descending order based on the values in a column."),
tags$li(tags$b("Page controls"), " - switch to specific page of data
within the table.")
)
)),
p(
tags$b(
"Note: Statistical disclosure control has been applied to protect
patient confidentiality. Therefore, the figures presented here
may not be additive and may differ from previous publications."
)
),
downloadButton(outputId = "download_glossary3",
label = "Download glossary",
class = "glossary"),
tags$head(
tags$style(".glossary { background-color: #0072B2; }
.glossary { color: #FFFFFF; }")
),
p(""),
wellPanel(
tags$style(
".well { background-color: #FFFFFF;
border: 0px solid #336699; }"
),
#Insert the reactive filters.
#We have SIX filters at this point
# 1 - Hospital/Clinical type
# 2 - Activity Type
# 3 - Geography Type
# 4 - Geography
# 5 - Substance (Multiple)
# 6 - Measure
column(
4,
shinyWidgets::pickerInput(
inputId = "Hospital_Type2",
label = "Hospital type",
choices = hospital_types
),
shinyWidgets::pickerInput(
inputId = "Location2",
label = "Location",
choices = geography_list,
selected = "Scotland",
options = list(size=10,
`live-search`=TRUE)
),
downloadButton(outputId = "download_substances",
label = "Download data",
class = "substancesbutton"),
tags$head(
tags$style(".substancesbutton { background-color:
#0072B2; }
.substancesbutton { color: #FFFFFF; }")
)
),
column(
4,
uiOutput("time_trend_clinical_type2"),
uiOutput("time_trend_substance2")
),
column(
4,
shinyWidgets::pickerInput(
inputId = "Activity_Type2",
label = "Activity type",
choices = activity_type
),
shinyWidgets::pickerInput(
inputId = "Measure2",
label = "Measure",
choices = measures,
selected = "Rate"
)
)
),
#In the main panel of the tab, insert the substances plot
mainPanel(
width = 12,
plotlyOutput("substances_plot",
width = "1090px",
height = "500px"),
br(),
HTML("<button data-toggle = 'collapse' href = '#substances'
class = 'btn btn-primary' id = 'substances_link'>
<strong> Show/hide table </strong></button>"),
HTML("<div id = 'substances' class = 'collapse'>"),
br(),
dataTableOutput("substances_table"),
HTML("</div>"),
br(),
br()
)
#End of tab panel
),
##############################################.
############## Age/Sex tab ----
##############################################.
tabPanel(
"Age/sex",
icon = icon("child"),
style = "height: 95%; width: 95%; background-color: #FFFFFF;
border: 0px solid #FFFFFF;",
h3("Age/sex"),
p(
h4("Visualise drug-related hospital activity over time by patient
age group and sex (Scotland level only).")),
bs_accordion(id = "drhs_age_sex_text") %>%
bs_set_opts(panel_type = "primary") %>%
bs_append(title = "Data selection",
content = p("The toggle buttons allow
the data to be visualised in two ways:",
tags$ul(
tags$li(
tags$b("Line chart"),
icon("line-chart"),
" - displays trends for specific age and sex groups."
),
tags$li(
tags$b("Bar chart "),
icon("bar-chart"),
" - shows annual breakdowns by age group and sex."
)),
p("The charts can be modified using the drop down boxes:"),
p( tags$ul(style = "width:50%; float:left;",
tags$li("Hospital type: general acute or psychiatric
hospital data (or a combination);"),
tags$li("Clinical type: mental & behavioural stays,
accidental poisoning/overdose stays (or a combination);"),
tags$li("Activity type: stays, patients or new patients;"),
tags$li("Drug type: the type of drug associated with the
stay (multiple selection) (opioid sub categories are available if overdoses
are selected as Clinical type);")
),
tags$ul(style = "width:50%; float:left;",
tags$li("Measure: numbers, rates or percentages;"),
tags$li("Age group (Line chart only): patient age (multiple selection);"),
tags$li("Sex (Line chart only): patient sex (multiple selection); and,"),
tags$li("Financial year (Bar chart only): use the slider to select
year or the play button to visualise changes over time.")
)),
p(style = "width:100%; float:left;",
"To download your data selection as a CSV file, use the
'Download data' button under the filters.",
br(),br(),
"For technical information, please see the Introduction page.")
))%>%
bs_append(title = "Chart functions",
content = p("At the top-right corner of the
chart, you will see a toolbar with four buttons:",
tags$ul(
tags$li(
icon("camera"),
tags$b("Download plot as a png"),
" - save an image of the chart (not available in Internet Explorer)."
),
tags$li(
icon("search"),
tags$b("Zoom"),
" - click and drag within the chart area to focus on a specific part."
),
tags$li(
icon("move", lib = "glyphicon"),
tags$b("Pan"),
" - click and move the mouse in any direction to modify the chart axes."
),
tags$li(
icon("home"),
tags$b("Reset axes"),
" - click this button to return the axes to their default range."
)
),"Categories can be shown/hidden by clicking on labels in the
legend to the right of the chart."
)
)%>%
bs_append(title = "Table functions",
content = p(HTML("To view
your data selection in a table, use the <a href = '#age_and_sex_link'>
'Show/hide table' </a> button at the
bottom of the page."),
tags$ul(
tags$li(tags$b("Show entries"), " - change the number of rows shown
in the table using the drop-down box."),
tags$li(tags$b("Search"), " - enter text to search data for a specific word or
numerical value."),
tags$li(icon("sort", lib = "glyphicon"),
tags$b("Sort"), " - click to sort the table in ascending or
descending order based on the values in a column."),
tags$li(tags$b("Page controls"), " - switch to specific page of data
within the table.")
)
)),
p(
tags$b(
"Note: Statistical disclosure control has been applied to protect
patient confidentiality. Therefore, the figures presented here
may not be additive and may differ from previous publications."
)
),
downloadButton(outputId = "download_glossary4",
label = "Download glossary",
class = "glossary"),
tags$head(
tags$style(".glossary { background-color: #0072B2; }
.glossary { color: #FFFFFF; }")
),
p(""),
wellPanel(
tags$style(
".well { background-color: #FFFFFF;
border: 0px solid #336699; }"
),
#Insert the reactive filters.
#We have FOUR filters at this point
# 1 - Hospital/Clinical type
# 2 - Activity Type
# 3 - Substance (dependent on Hospital/Clinic Type)
# 4 - Measure
column(4,
shinyWidgets::pickerInput(
inputId = "Hospital_Type3",
label = "Hospital type",
choices = hospital_types
),
uiOutput("age_sex_substance")),
column(
4,
uiOutput("age_sex_clinical_type"),
shinyWidgets::pickerInput(
inputId = "Measure3",
label = "Measure",
choices = measures,
selected = "Rate"
)
),
column(4,
shinyWidgets::pickerInput(
inputId = "Activity_Type3",
label = "Activity type",
choices = activity_type,
selected = "Stays"
))
),
#In the main panel of the tab, insert the time trend plot
mainPanel(width = 12,
tabsetPanel(
type = "pills",
tabPanel(
"Time Trend",
tags$style(
HTML("
.tabbable > .nav > li > a[data-value = 'Bar Chart'] {background-color: #D3D3D3; color: #000000;}
.tabbable > .nav > li > a[data-value = 'Time Trend'] {background-color: #D3D3D3; color: #000000;}
.tabbable > .nav > li[class = active] > a {background-color: #0072B2;color: #FFFFFF;}
")