-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.R
233 lines (202 loc) · 7.94 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
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
#produce content displayed through ui
#---------------------------------------
# Load packages (only matters for publishing on shiny.io)
library(tidyverse)
library(DT)
library(shinyjs)
#-----------------------------------
# Basic Structure
server <- function(input, output, session){
#------------------------------------
load(".RData")
#------------------------------------
# Get current time
output$currentTime <- renderText({
# Refresh every second
invalidateLater(1000, session)
# Output server time
format(Sys.time())
})
#-----------------------------------
#Tracker Outputs
#Load the progress tracker output
output$plotProgress <- renderPlot({
tbPriorities %>%
ggplot(aes(fill = Progress, x = Count, y = "")) +
geom_bar(position = position_fill(reverse = TRUE),
stat = "identity",
width = 1) +
coord_flip() +
theme(
legend.position = "none",
# legend.justification = "right",
plot.title = element_text(size=18, face="bold", margin=margin(c(0,0,8,0))),
# legend.margin=margin(c(0,0,-4,0)),
# legend.title=element_text(size=16),
# legend.text=element_text(size=16),
panel.spacing = margin(c(0,0,0,0)),
panel.border = element_rect(colour = "black", fill=NA, size=0.5),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x = element_blank(),
panel.background = element_blank()
) +
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
scale_fill_manual(values=ggpalette1, drop = FALSE, name="Progress")
}, height = "auto")
# Text for timeline vis description
output$timelineText <- renderText({
# Refresh every minute
invalidateLater(60000, session)
# Return text explaining when the 100 Days of Action began, and if
# they are still happening, the current date and number. If they are
# no longer happening, return the date they ended.
ifelse(which(tbDays$Date == Sys.Date())<=101,
paste0("Mayor Scott took office on 12/8/20. Today is day ",
which(tbDays$Date == Sys.Date()-1),
"."
),
paste0("The 100 Days of Action began when Mayor Scott took office ",
"on 12/8/20. The last day was 3/18/21."
)
)
})
output$progressLegend <- renderUI({
div(class="legend",
div(style="background:#199eb4"), p("Complete"),
div(style=paste0("background:", bc_gold, ";")), p("In progress"),
div(style="background:whiteSmoke;"), p("Not yet started")
)
})
#load the timeline tracker output
output$plotTimeline <- renderPlot({
# Refresh every minute
invalidateLater(60000, session)
tbDays %>%
filter(`Mayoral First 100 Days Number` < 101) %>%
mutate(Status = factor(sapply(.$Date,function(x) {ifelse(x > Sys.Date(), "Remaining", ifelse(x == Sys.Date(), "Current","Past"))}),
levels=c("Past", "Current","Remaining")),
Total = 1) %>%
ggplot(aes(fill = Status, x = Total, y = "")) +
geom_bar(position = position_fill(reverse = TRUE),
stat = "identity",
width = 1) +
coord_flip() +
theme(
legend.position = "none",
panel.border = element_rect(colour = "black", fill=NA, size=0.5),
panel.spacing = margin(c(0,0,0,0)),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank(),
axis.text.x = element_blank(),
panel.background = element_blank()
) +
scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
scale_fill_manual(values=ggpalette2, drop=FALSE, name = "Status")
}, height = "auto")
legendItemSpacing <- "padding-right:4x;"
output$timelineLegend <- renderUI({
div(class="legend",
div(style="background:DimGrey"), p("Past"),
div(style=paste0("background:", bc_gold, ";")), p("Current"),
div(style="background:whiteSmoke;"), p("Remaining")
)
})
# Table with progress on all priority areas and actions
output$tbPriorities = DT::renderDataTable({
DT::datatable(
cbind(tbCommittees, 'Expand' = '▼'),
options = list(
dom = 'ft',
searching = F,
pageLength = 10,
columnDefs = list(
list(width = '300px', targets = c(3)),
list(width = '18px', targets = c(1)),
list(width = '172px', targets = c(4)),
list(visible = FALSE, targets = c(0, 2, 4, 5)),
list(orderable = FALSE, targets = "_all"),
list(className = 'details-control', targets = c(7)),
list(className = 'dt-center', targets = c(0,4))
),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'font-size': '18px'});",
"}")
),
colnames = c("", "", "", "Priority Area", "", "", "Progress", ""),
callback = JS("
table.column(6).nodes().to$().css({cursor: 'pointer'});
var format = function(d) {
if (d[5] == null) {
return '<p>There is no additional data to display here.</p>';
} else {
var result = '<table class=\"priorities-hierarchy-2\" style=\"font-size:16px;padding:0.5em;margin-left:32px;width:calc(100% - 24px);\">';
result += '<tr><th>Action</th><th>Status</th><th>Parties Responsible</th></tr>';
for (var i in d[5]){
result += '<tr >';
for (var j in d[5][i]) {
if (j == 0) {
result += '<td style=\"width:300px;\">' + d[5][i][j] + '</td>';
} else if (j == 1) {
result += '<td style=\"width:120px;\">' + d[5][i][j] + '</td>';
} else {
result += '<td>' + d[5][i][j] + '</td>';
}
}
result += '</tr>';
}
result += '</table>';
return result;
}
};
table.on('click', 'td.details-control', function() {
var td = $(this), row = table.row(td.closest('tr'));
if (row.child.isShown()) {
row.child.hide();
td.html('▼');
} else {
row.child(format(row.data())).show();
td.html('▲');
}
});"
)
,escape = F
) %>%
formatStyle(
names(tbCommittees),
target = 'row',
backgroundColor = 'white', fontSize = '18px') %>%
formatStyle('Priority Area', fontSize = '18px', fontWeight = 'bold') %>%
formatStyle('Progress', fontSize = '18px', fontWeight = 300) %>%
formatStyle('Expand', fontSize = '18px', color="grey", fontWeight = 300)
})
#------------------------------------
# Download button for data on all actions
output$downloadActions <- downloadHandler(
filename = function() {
paste(Sys.Date(), "-mayor-scott-transition-tracker-actions.csv", sep="")
},
content = function(file) {
write.csv(tbPriorities %>%
rename(Status = Progress,
`Priority Area` = Committee) %>%
select(`Action #`, Action, Status, `Priority Area`,`Parties Responsible`),
file,
row.names=FALSE)
}
)
#-------------------------------------
# Updates table outputs
output$updateContent <- renderUI({
div(class="Updates",
HTML(toString(updateText))
)
})
}