-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
utils.R
29 lines (26 loc) · 851 Bytes
/
utils.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
.onLoad <- function(libname, pkgname) {
# register a handler to decode the timeline data passed from JS to R
# because the default way of decoding it in shiny flattens a data.frame
# to a vector
shiny::registerInputHandler("timevisDF", function(data, ...) {
jsonlite::fromJSON(jsonlite::toJSON(data, auto_unbox = TRUE))
})
}
# Check if an argument is a single boolean value
is.bool <- function(x) {
is.logical(x) && length(x) == 1
}
# Convert a data.frame to a list of lists (the data format that D3 uses)
dataframeToD3 <- function(df) {
if (missing(df) || is.null(df)) {
return(list())
}
if (!is.data.frame(df)) {
stop("timevis: the input must be a dataframe", call. = FALSE)
}
row.names(df) <- NULL
apply(df, 1, function(row) as.list(row[!is.na(row)]))
}
#' @importFrom magrittr %>%
#' @export
magrittr::`%>%`