-
Notifications
You must be signed in to change notification settings - Fork 9
/
tables.R
135 lines (127 loc) · 3.4 KB
/
tables.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
output$reports_by_week <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
as.data.frame(
tbl_df(
dcast(
dates_received() %>%
mutate(Week = format(time, "%Y-%m-%d"),
Week = as.POSIXct(Week)) %>%
select(Week, `Adverse Events` = count),
Week ~ drug,
value.var = "Adverse Events"
)
) %>%
arrange(desc(Week))
)
})
}, options = list(searching = FALSE,
LengthChange = I("false")))
output$outcomes <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
tbl_df(
outcomes()) %>%
arrange(Outcome)
})
}, options = list(searching = FALSE,
paging = FALSE,
LengthChange = I("false"))
)
output$outcome_shares <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
dcast(
tbl_df(
melt(outcomes(),
"Outcome")) %>%
group_by(variable) %>%
mutate(total_report_count = sum(value),
share = value / total_report_count) %>%
ungroup %>%
mutate(share = percent(share)) %>%
select(Outcome, variable, share),
Outcome ~ variable,
value.var = "share")
})
}, options = list(searching = FALSE,
paging = FALSE,
LengthChange = I("false"))
)
output$reactions <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
reactionoutcomes()
})
}, options = list(searching = FALSE,
LengthChange = I("false")))
output$deaths <- renderText({
paste(
comma((tbl_df(
fda_query("/drug/event.json") %>%
fda_count("patient.reaction.reactionoutcome") %>%
fda_exec()) %>%
filter(term == 5))$count),
"deaths")
})
ages_for_table <- reactive({
ages() %>%
rename(Age = term) %>%
mutate(Age = cut(Age,
breaks = seq(0, 120,
5),
include.lowest = TRUE)) %>%
group_by(drug) %>%
mutate(total_report_count = sum(count),
share = round(count / total_report_count, 4)) %>%
ungroup %>%
mutate(share = share)
})
output$age_shares <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
tbl_df(
dcast(
ages_for_table() %>%
select(Age, drug, share),
Age ~ drug,
value.var = "share", fill = 0,
fun.aggregate = sum)) %>%
mutate_each(funs(percent), -c(1))
})
}, options = list(searching = FALSE,
paging = FALSE,
LengthChange = I("false"))
)
output$ages_counts <- renderDataTable({
validate(
need(input$run_button > 0,
'Select some drugs and press the "Retrieve data" button.')
)
isolate({
dcast(
ages_for_table() %>%
select(Age, drug, count),
Age ~ drug,
value.var = "count", fill = 0,
fun.aggregate = sum)
})
}, options = list(searching = FALSE,
paging = FALSE,
LengthChange = I("false"))
)