#' Save graph to html file
#'
#' @param graph The graph to save
#' @param path The path where to write the file
#' @param libdir The directory where to write the graphical libs
#' @export
save_html_to_path <- function(graph, path, libdir = "lib") {
if (tools::file_ext(path) != "html") {
stop('Use ".html" as extension.')
}
abs_root_dir <- file.path(getwd(), dirname(path))
dir.create(abs_root_dir, showWarnings = FALSE)
abs_file_path <- file.path(abs_root_dir, basename(path))
abs_lib_path <- file.path(abs_root_dir, libdir)
htmltools::save_html(graph, abs_file_path, libdir = abs_lib_path)
}
#' @export
viz_ts <- function(ts, title = NULL, title_from_col = F, group="ensync"){
if (title_from_col) {
title <- paste(colnames(ts), sep="_")
}
dyg <- ts %>%
dygraph(main = title, group = group, width = "100%") %>%
dySeries() %>%
dyRangeSelector()
dyg
}
#' @export
viz_tss <- function(ts, title_from_col = F, group="ensync"){
dyg_lst <- lapply(colnames(ts), function(col) viz_ts(ts[,col], title_from_col=title_from_col))
dyg_lst
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.