Created
January 9, 2019 04:27
-
-
Save dantonnoriega/0eab04f889ca95af85f183d85e52279b to your computer and use it in GitHub Desktop.
my attempt to create a widgetframe with a dark background. hackish. seems to shift xaringan presentation oddly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove any old tmp files | |
old_tmp_files <- list.files(pattern = '^tmp', include.dirs = TRUE, full.names = TRUE) | |
invisible(unlink(old_tmp_files, recursive = TRUE)) | |
# create a dark widget frame via work around | |
dark_widgetframe <- | |
function(widget, background = '#666666FF', width = '100%', height = 420) { | |
file = tempfile(pattern = "tmp", tmpdir = '.', fileext = ".html") | |
selfcontained = FALSE | |
libdir = NULL | |
knitrOptions = list() | |
# code directly from widgetframe::frameWidget() | |
parentWidget <- NULL | |
if ("widgetframe" %in% class(widget)) { | |
parentWidget <- widget | |
} else { | |
# added width, height | |
parentWidget <- | |
widgetframe::frameWidget(widget, width = width, height = height) | |
} | |
childDir <- file.path( | |
dirname(file), | |
paste0(tools::file_path_sans_ext(basename(file)), "_widget")) | |
dir.create(childDir) | |
parentWidget$x$url <- | |
paste0(tools::file_path_sans_ext(basename(file)), "_widget/index.html") | |
childWidget <- attr(parentWidget$x, "widget") | |
oldwd <- setwd(childDir) | |
htmlwidgets::saveWidget( | |
childWidget, "index.html", | |
selfcontained = selfcontained, | |
libdir = libdir, background = background, knitrOptions = knitrOptions) | |
setwd(oldwd) | |
htmlwidgets::saveWidget( | |
parentWidget, file, selfcontained = selfcontained, | |
libdir = libdir, background = background, knitrOptions = knitrOptions) | |
lines <- readLines(file, warn = FALSE, encoding = "UTF-8")[-1] | |
html_raw <- htmltools:::paste8(lines, collapse = "\r\n") | |
return(htmltools::HTML(html_raw)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment