/
utils.R
33 lines (30 loc) · 1015 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
30
31
32
33
.onLoad <- function(libname, pkgname) {
shiny::registerInputHandler("regionsDF", function(data, ...) {
data <- jsonlite::fromJSON(data)
if(length(data) == 0) {
tibble::tibble(start = numeric(0), end = numeric(0))
} else {
tibble::as_tibble(data)
}
})
}
callJS <- function() {
message <- Filter(function(x) !is.symbol(x), as.list(parent.frame(1)))
session <- shiny::getDefaultReactiveDomain()
if (methods::is(message$id, "wavesurfer")) {
widget <- message$id
message$id <- NULL
widget$x$api <- c(widget$x$api, list(message))
return(widget)
} else if (is.character(message$id)) {
method <- paste0("wavesurfer:", message$method)
session$sendCustomMessage(method, message)
return(message$id)
} else {
stop("The `id` argument must be either a wavesurfer htmlwidget or an ID of a wavesurfer htmlwidget.", call. = FALSE)
}
}
#' @importFrom utils packageVersion
tidyr_new_interface <- function() {
utils::packageVersion("tidyr") > "0.8.99"
}