Skip to content

Commit

Permalink
Merge pull request #50 from dmurdoch/keepclass6
Browse files Browse the repository at this point in the history
Preserve the class of widgets that are passed to combineWidgets.
  • Loading branch information
bthieurmel authored Jan 30, 2018
2 parents 29d6bfb + 278281a commit 6961add
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export(staticPlot)
exportClasses(MWController)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(htmltools,tagGetAttribute)
importFrom(htmlwidgets,getDependency)
importFrom(methods,is)
importFrom(methods,new)
Expand Down
19 changes: 15 additions & 4 deletions R/combine_widgets.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#' }
#'
#' @export
#' @importFrom htmltools tagGetAttribute
combineWidgets <- function(..., list = NULL, nrow = NULL, ncol = NULL, title = NULL,
rowsize = 1, colsize = 1, byrow = TRUE,
titleCSS = "",
Expand Down Expand Up @@ -261,19 +262,29 @@ preRenderCombinedWidgets <- function(x) {
})
}

# Get the HTML class for each widget, plus "cw-widget"
elementClass <- sapply(widgets[1:ncells], function(w) {
result <- NULL
if (inherits(w, "htmlwidget"))
result <- class(w)[1]
else if (inherits(w, "shiny.tag"))
result <- tagGetAttribute(w, "class")
paste(result, "cw-widget")
})

# Construct the html of the combined widget
dirClass <- ifelse(x$params$byrow, "cw-by-row", "cw-by-col")

widgetEL <- mapply(
function(id, size) {
function(id, size, class) {
sprintf('<div class="cw-col" style="flex:%s;-webkit-flex:%s">
<div id="%s" class="cw-widget" style="width:100%%;height:100%%"></div>
<div id="%s" class="%s" style="width:100%%;height:100%%"></div>
</div>',
size, size, id)
size, size, id, class)
},
id = elementId,
size = rep(colsize, length.out = ncells)
size = rep(colsize, length.out = ncells),
class = elementClass
)

rowsEl <- lapply(1:nrow, function(i) {
Expand Down

0 comments on commit 6961add

Please sign in to comment.