diff --git a/R/timevisBasic.R b/R/timevisBasic.R index ca20e69..175678b 100644 --- a/R/timevisBasic.R +++ b/R/timevisBasic.R @@ -26,8 +26,8 @@ #' } #' ) #' @export -timevis <- function(data = list(), width = NULL, height = NULL, elementId = NULL) { - items <- data +timevis <- function(data, width = NULL, height = NULL, elementId = NULL) { + items <- dataframeToD3(data) # forward options using x x = list( @@ -83,4 +83,16 @@ timevisBasic_html <- function(id, style, class, ...) { htmltools::tags$button("-") ) ) +} + +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)])) } \ No newline at end of file diff --git a/man/timevis.Rd b/man/timevis.Rd index 9d66187..2090ace 100644 --- a/man/timevis.Rd +++ b/man/timevis.Rd @@ -4,7 +4,7 @@ \alias{timevis} \title{Create a basic timeline visualization} \usage{ -timevis(data = list(), width = NULL, height = NULL, elementId = NULL) +timevis(data, width = NULL, height = NULL, elementId = NULL) } \description{ Create a basic timeline visualization