From 41ef91c0795f134fdd3d1e06065afbba479b67ea Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Thu, 2 Feb 2017 21:23:01 -0600 Subject: [PATCH] Respect an 'after_widget' field to control the order of dependencies. Fixes #254 --- R/htmlwidgets.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/htmlwidgets.R b/R/htmlwidgets.R index 5a7ca032..0de93c2d 100644 --- a/R/htmlwidgets.R +++ b/R/htmlwidgets.R @@ -206,13 +206,22 @@ toHTML <- function(x, standalone = FALSE, knitrOptions = NULL) { ) } ) - html <- htmltools::attachDependencies(html, - c(widget_dependencies(class(x)[1], attr(x, 'package')), - x$dependencies) - ) - htmltools::browsable(html) + # make sure we're working with a list of dependencies + if (inherits(x$dependencies, "html_dependency")) { + x$dependencies <- list(x$dependencies) + } + # collect and attach dependencies + deps <- widget_dependencies(class(x)[1], attr(x, 'package')) + for (i in seq_along(x$dependencies)) { + dep <- x$dependencies[[i]] + append <- dep$after_widget %||% TRUE + deps <- if (append) c(deps, list(dep)) else c(list(dep), deps) + } + html <- htmltools::attachDependencies(html, deps) + + htmltools::browsable(html) }