-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
158 lines (118 loc) · 4.54 KB
/
server.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
########################
# server logic
########################
server <- function(input, output) {
# dates <- reactive({
# range(data$info$`Final Report Date`)
# })
### Value box: Special Investigation Reports
output$numReports <- renderValueBox({
numReports(data$info)
})
### Value box: Recent Reports from last 6 months
output$recentReports <- renderValueBox({
recentReports(data$info)
})
### Value box: Allegations
output$numAllegations <- renderValueBox({
numAllegations(data$violations)
})
### Value box: Violations Established
output$numViolations <- renderValueBox({
numViolations(data$violations)
})
### Reports by Year
output$reportsByYear <- renderPlotly({
reportsByYear(data$info)
})
### Violations by Year - Overall
output$violationsByYearOverall <- renderPlotly({
violationsByYearOverall(data$violations, data$info)
})
### Violations by Year - Established
output$violationsByYearEst <- renderPlotly({
violationsByYearEst(data$violations, data$info)
})
### Violations by Year - Not-Established
output$violationsByYearNEst <- renderPlotly({
violationsByYearNEst(data$violations, data$info)
})
### Reports by Facility
output$reportsByFacility <- renderPlotly({
data$info <- data$info[year(data$info$`Final Report Date`)>=input$rangeSIR[1] & year(data$info$`Final Report Date`)<=input$rangeSIR[2],]
reportsByFacility(data$info)
})
### Violations by Facility - Overall
output$violationsByFacilityOverall <- renderPlotly({
data$info <- data$info[year(data$info$`Final Report Date`)>=input$rangeViolation[1] & year(data$info$`Final Report Date`)<=input$rangeViolation[2],]
violationsByFacilityOverall(data$violations, data$info)
})
### Violations by Facility - Established
output$violationsByFacilityEst <- renderPlotly({
data$info <- data$info[year(data$info$`Final Report Date`)>=input$rangeViolation[1] & year(data$info$`Final Report Date`)<=input$rangeViolation[2],]
violationsByFacilityEst(data$violations, data$info)
})
### Violations by Facility - Not Established
output$violationsByFacilityNEst <- renderPlotly({
data$info <- data$info[year(data$info$`Final Report Date`)>=input$rangeViolation[1] & year(data$info$`Final Report Date`)<=input$rangeViolation[2],]
violationsByFacilityNEst(data$violations, data$info)
})
### Proportion of Allegations with Violation Established
output$proportionAllegations <- renderPlotly({
proportionAllegations(data$violations, data$info)
})
### Number of Allegations per SIR
output$numAllegationsSIR <- renderPlotly({
numAllegationsSIR(data$violations)
})
### SIRs with at least One Violation Established
output$SIRSwithOneViolation <- renderPlotly({
SIRSwithOneViolation(data$violations, data$info)
})
### Explorable Data Table: Report Information
output$reportInformationTable <- renderDataTable(reportInformationTable(data$info, input))
### Explorable Data Table: Alleged Violations
output$allegedViolationsTable <- renderDataTable(allegedViolationsTable(data$violations, data$info, input))
### Explorable Data Table: Applicable Rules
output$applicableRulesTable <- renderDataTable(applicableRulesTable(data$info, data$rules, input))
### Download data
output$downBtn <- output$downBtn2 <- output$downBtn3 <- downloadHandler(
filename = function() { "DATA.xlsx" },
content = function(file) {
l <- list("INFORMATION" = info, "VIOLATIONS" = violations, "RULES" = rules)
write.xlsx(l, file) }
)
### Update data
### When the update button is selected, run the PDF scraping and reformatting code
### TODO: then update the data (and all reactive plots/values) by reading in the new/updated excel file
# data<- eventReactive(input$update, {
# print("Updating Data")
#
# updateData(data_path)
#
# })
observeEvent(input$update, {
print("Updating Data")
updateData(data_path)
})
observeEvent(input$update2, {
print("Updating Data")
updateData(data_path)
})
observeEvent(input$update3, {
print("Updating Data")
updateData(data_path)
})
### Map: Number of Reports
output$mapReports <- renderLeaflet(
mapReports(data$violations, data$info, zips)
)
### Map: Number of Allegations
output$mapAllegations <- renderLeaflet(
mapAllegations(data$violations, data$info, zips)
)
### Map: Number of Violations
output$mapViolations <- renderLeaflet(
mapViolations(data$violations, data$info, zips)
)
}