-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.R
55 lines (50 loc) · 1.55 KB
/
utilities.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
# Helper functions----
is_date <- function(df, str) {
str_s <- as.name(str)
summarise(df, is.Date(!!str_s) | is.POSIXct(!!str_s)) %>% pull
}
parse_date <- function(df, str, format, tz = "America/Regina") {
str_s <- as.name(str)
mutate(df, !!str_s := as.POSIXct(strptime(!!str_s,
format = format)))
}
dynamic_filter <- function(df, variables, conditions){
filter_conditions <- purrr::map2(variables, conditions,
function(var, cond) {
if (is.null(cond)) {
return(NULL)
} else {
# Construct list of quoted filtering conditions
return(rlang::quo(!!sym(var) %in% cond))
}
}) %>%
Filter(purrr::negate(is.null), .)
dplyr::filter(df, !!!filter_conditions)
}
duplicatedReactive <- function(signal){
values <- reactiveValues(val = "")
observe({
values$val <- signal()
})
reactive(values$val)
}
# Config parameters----
# Date-time formats to try on data
datetime_formats <- c(
"%m/%d/%Y %H:%M",
"%m/%d/%Y %H%M",
"%m/%d/%Y",
"%Y/%m/%d %H:%M",
"%Y/%m/%d %H%M",
"%Y/%m/%d",
"%Y%m%d %H:%M",
"%Y%m%d %H%M",
"%Y%m%d"
)
# Default values for variables
date_col <- "Date"
y_col <- "Actual"
# Set ggplot theme
theme_set(theme_minimal())
# Increase input file limit to 10MB
options(shiny.maxRequestSize = 10*1024^2)