forked from statwonk/openfda-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.R
74 lines (70 loc) · 1.8 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
output$reports_by_week <- renderDataTable({
if(is.null(input$drug))
return()
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({
if(is.null(input$drug))
return()
isolate({
tbl_df(
outcomes()) %>%
arrange(Outcome)
})
}, options = list(searching = FALSE,
paging = FALSE,
LengthChange = I("false"))
)
output$outcome_shares <- renderDataTable({
if(is.null(input$drug))
return()
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({
if(is.null(input$drug))
return()
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")
})