-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path1-dashboard.Rmd
100 lines (82 loc) · 2.36 KB
/
1-dashboard.Rmd
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
---
title: "Adverse Events for Keytruda"
output:
flexdashboard::flex_dashboard:
orientation: row
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(openfda)
library(ggthemes)
library(gt)
get_adverse <- function(gender, brand_name) {
fda_query("/drug/event.json") %>%
fda_filter("patient.drug.openfda.brand_name", brand_name) %>%
fda_filter("patient.patientsex", gender) %>%
fda_count("patient.reaction.reactionmeddrapt.exact") %>%
fda_exec()
}
total_events<- function(brand_name){
fda_query("/drug/event.json") %>%
fda_filter("patient.drug.openfda.brand_name", brand_name) %>%
fda_count("patient.reaction.reactionmeddrapt.exact") %>%
fda_exec()
}
serious_events<- function(brand_name){
fda_query("/drug/event.json") %>%
fda_filter("patient.drug.openfda.brand_name", brand_name) %>%
fda_count("serious") %>%
fda_exec()
}
drug<- 'Keytruda'
female<-get_adverse(2, drug) %>% mutate(sex = 'female')
male<-get_adverse(1, drug)%>% mutate(sex = 'male')
all<- total_events(drug)
total_count<- sum(all$count)
serious<-serious_events(drug) %>% filter(term==1) %>% pull(count)
```
Row
-----------------------------------------------------------------------
### Total Events Reported
```{r}
valueBox(total_count)
```
### Serious Events
```{r}
valueBox(serious)
```
Row
-----------------------------------------------------------------------
### All Events
```{r}
all %>%
top_n(10, count) %>%
ggplot()+
geom_bar(aes(x=reorder(term, count), y=count), stat='identity', fill ="#3686D3")+
coord_flip()+
theme_tufte()+
xlab('')+
ylab('Events Reported')
```
### Events By Sex
```{r}
rbind(male,female) %>%
mutate(term=str_to_title(term)) %>%
pivot_wider(names_from=sex, values_from=count) %>%
mutate(Total=female+male) %>%
top_n(10, Total) %>%
gt(rowname_col="term") %>% tab_header(
title = md("Adverse Events"),
subtitle = "The top ten most reported events"
) %>% tab_source_note("All data queried from openFDA") %>%
tab_stubhead(label= 'Patient Reaction') %>%
tab_spanner(label = "By sex",
columns = c(female, male)) %>%
tab_spanner(label= 'Total Cases',
columns = Total) %>%
fmt_number(columns = c(female, male, Total), sep_mark = ',', decimals=0) %>%
cols_label(Total = '',
female = 'Female',
male= 'Male')
```