forked from dreamRs/shinyWidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onLoad.R
40 lines (40 loc) · 1.01 KB
/
onLoad.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
#' Adds the content of www to shinyWidgets/
#'
#' @importFrom shiny addResourcePath registerInputHandler
#'
#' @noRd
#'
.onLoad <- function(...) {
shiny::addResourcePath('shinyWidgets', system.file('www', package = 'shinyWidgets'))
shiny::registerInputHandler("air.date", function(data, ...) {
if (is.null(data)) {
NULL
} else {
res <- try(as.Date(unlist(data)), silent = TRUE)
if ("try-error" %in% class(res)) {
warning("Failed to parse dates!")
# as.Date(NA)
data
} else {
res
}
}
}, force = TRUE)
shiny::registerInputHandler("air.datetime", function(data, ...) {
parse_datetime <- function(x) {
as.POSIXct(x = x/1000, origin = "1970-01-01")
}
if (is.null(data)) {
NULL
} else {
res <- try(parse_datetime(unlist(data)), silent = TRUE)
if ("try-error" %in% class(res)) {
warning("Failed to parse dates!")
# as.Date(NA)
data
} else {
res
}
}
}, force = TRUE)
}