Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions R/savewidget.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,30 @@ saveWidget <- function(widget, file, selfcontained = TRUE, libdir = NULL,
background <- sprintf("rgba(%d,%d,%d,%f)", bgcol[1,1], bgcol[2,1], bgcol[3,1], bgcol[4,1]/255)
}

# convert to HTML tags
html <- toHTML(widget, standalone = TRUE, knitrOptions = knitrOptions)

# form a path for dependenent files
if (is.null(libdir)){
libdir <- paste(tools::file_path_sans_ext(basename(file)), "_files",
sep = "")
}

# convert to HTML tags
isWidget <- inherits(widget, "htmlwidget")
isTags <- inherits(widget, c("shiny.tag", "shiny.tag.list"))
html <- if (isWidget) {
toHTML(widget, standalone = TRUE, knitrOptions = knitrOptions)
} else if (isTags) {
widget
} else {
stop("`widget` must be an object of class 'htmlwidget' or 'shiny.tag' or 'shiny.tag.list'.", call. = FALSE)
}

# selfcontained isn't yet supported in htmltools, but maybe it will someday
# https://github.com/rstudio/htmltools/issues/73
if (isTags && selfcontained) {
warning("`selfcontained` is not yet supported for HTML tags (just HTML widgets).", call. = FALSE)
selfcontained <- FALSE
}

# make it self-contained if requested
if (selfcontained) {

Expand Down