/
functions.R
33 lines (25 loc) · 1012 Bytes
/
functions.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
get_info <- function(data, var_name, FUNC, icon) {
value = FUNC(data[[var_name]], na.rm=T)
FUNC_name = toTitleCase(as.character(substitute(FUNC)))
title = paste(FUNC_name, var_name)
if (FUNC_name %in% c('Min','Max')) {
state = sort(data$'State Abbr'[data[,var_name]==value])
state = paste(state, collapse = "/")
} else {
state=NULL
}
colFormat = value_formats[value_formats$col==var_name,'format']
valueStr = ifelse(colFormat==1,
formatC(value,format="f", big.mark = ",",digits=0),
paste0(formatC(value*100,format="f",big.mark=",",digits=2), '%'))
return (infoBox(title=title, subtitle=state, value=valueStr, icon = icon, fill=T))
}
get_axis <- function(var_name) {
colFormat = value_formats[value_formats$col==var_name,'format']
if (colFormat==1){
y_axis_format = scale_y_continuous(labels = scales::comma)
} else {
y_axis_format = scale_y_continuous(labels = scales::percent)
}
return (y_axis_format)
}