Skip to content

Add reportTheme arg to shinyWidgetOutput() #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: htmlwidgets
Type: Package
Title: HTML Widgets for R
Version: 1.5.1.9000
Version: 1.5.1.9001
Authors@R: c(
person("Ramnath", "Vaidyanathan", role = c("aut", "cph")),
person("Yihui", "Xie", role = c("aut")),
Expand All @@ -25,4 +25,4 @@ Suggests:
Enhances: shiny (>= 1.1)
URL: https://github.com/ramnathv/htmlwidgets
BugReports: https://github.com/ramnathv/htmlwidgets/issues
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
22 changes: 19 additions & 3 deletions R/htmlwidgets.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ createWidget <- function(name,
#' function.
#' @param reportSize Should the widget's container size be reported in the
#' shiny session's client data?
#' @param reportTheme Should the widget's container styles (e.g., colors and fonts)
#' be reported in the shiny session's client data?
#' @param expr An expression that generates an HTML widget (or a
#' \href{https://rstudio.github.io/promises/}{promise} of an HTML widget).
#' @param env The environment in which to evaluate \code{expr}.
Expand Down Expand Up @@ -386,13 +388,27 @@ createWidget <- function(name,
#'
#' @export
shinyWidgetOutput <- function(outputId, name, width, height, package = name,
inline = FALSE, reportSize = FALSE) {
inline = FALSE, reportSize = FALSE, reportTheme = FALSE) {

checkShinyVersion()

# Theme reporting requires this shiny feature
# https://github.com/rstudio/shiny/pull/2740/files
if (reportTheme &&
nzchar(system.file(package = "shiny")) &&
packageVersion("shiny") < "1.4.0.9003") {
message("`reportTheme = TRUE` requires shiny v.1.4.0.9003 or higher. Consider upgrading shiny.")
}

# generate html
html <- htmltools::tagList(
widget_html(name, package, id = outputId,
class = paste0(name, " html-widget html-widget-output", if (reportSize) " shiny-report-size"),
widget_html(
name, package, id = outputId,
class = paste0(
name, " html-widget html-widget-output",
if (reportSize) " shiny-report-size",
if (reportTheme) " shiny-report-theme"
),
style = sprintf("width:%s; height:%s; %s",
htmltools::validateCssUnit(width),
htmltools::validateCssUnit(height),
Expand Down
2 changes: 2 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ htmlwidgets 1.5.1.9000

* Fixed an issue with passing named function declarations to `JS()` and `onRender()` (introduced by v1.4). (#356)

* Added a `reportTheme` argument to `shinyWidgetOutput()`. If `TRUE`, CSS styles of the widget's output container are made available to `shiny::getCurrentOutputInfo()`, making it possible to provide 'smart' styling defaults in a `renderWidget()` context. (#361)

htmlwidgets 1.5.1
-------------------------------------------------------

Expand Down
14 changes: 11 additions & 3 deletions man/createWidget.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions man/htmlwidgets-shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions man/saveWidget.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions man/sizingPolicy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.