From b5bb62b9cab677333c48078fc7d87f9fc2f78977 Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 10 Feb 2021 17:35:07 -0600 Subject: [PATCH 01/20] Allow gaugeSectors() to updated on redraw (and also add bslib integration) --- R/gauge.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/gauge.R b/R/gauge.R index e778b518..448ceb6e 100644 --- a/R/gauge.R +++ b/R/gauge.R @@ -127,6 +127,7 @@ gaugeSectors <- function(success = NULL, warning = NULL, danger = NULL, ), class = "gaugeSectors" ) +<<<<<<< HEAD } resolveAccentColors <- function(colors, theme) { @@ -152,6 +153,21 @@ getSassAccentColors <- function(theme, accents = accent_colors()) { ) } +======= +} + +resolveSectorColors <- function(sectors, accentMap) { + sectors$ranges <- lapply(sectors$ranges, function(x) { + if (is_accent_color(x$color)) { + x$color <- accentMap[[x$color]] + } + x$color <- htmltools::parseCssColors(x$color) + x + }) + sectors +} + +>>>>>>> 30b38db (Allow gaugeSectors() to updated on redraw (and also add bslib integration)) #' Shiny bindings for gauge #' From f54ee76c4426b66ea388ba6c09a3a00825af5da1 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 11 Feb 2021 14:06:21 -0600 Subject: [PATCH 02/20] Make value boxes dynamically themeable --- R/gauge.R | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/R/gauge.R b/R/gauge.R index 448ceb6e..e778b518 100644 --- a/R/gauge.R +++ b/R/gauge.R @@ -127,7 +127,6 @@ gaugeSectors <- function(success = NULL, warning = NULL, danger = NULL, ), class = "gaugeSectors" ) -<<<<<<< HEAD } resolveAccentColors <- function(colors, theme) { @@ -153,21 +152,6 @@ getSassAccentColors <- function(theme, accents = accent_colors()) { ) } -======= -} - -resolveSectorColors <- function(sectors, accentMap) { - sectors$ranges <- lapply(sectors$ranges, function(x) { - if (is_accent_color(x$color)) { - x$color <- accentMap[[x$color]] - } - x$color <- htmltools::parseCssColors(x$color) - x - }) - sectors -} - ->>>>>>> 30b38db (Allow gaugeSectors() to updated on redraw (and also add bslib integration)) #' Shiny bindings for gauge #' From 90deed45eb915a4af32550439ce77369532a2cf5 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 9 Feb 2021 17:59:03 -0600 Subject: [PATCH 03/20] wip bslib integration --- DESCRIPTION | 1 + NEWS.md | 21 + R/dependencies.R | 2 + R/flex_dashboard.R | 104 ++- .../flex_dashboard/resources/default.html | 8 +- .../resources/flexdashboard.scss | 692 ++++++++++++++++++ 6 files changed, 786 insertions(+), 42 deletions(-) create mode 100644 inst/rmarkdown/templates/flex_dashboard/resources/flexdashboard.scss diff --git a/DESCRIPTION b/DESCRIPTION index fde27780..419edb6d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,3 +49,4 @@ LazyData: TRUE License: MIT + file LICENSE RoxygenNote: 7.1.1 Config/testthat/edition: 3 +Remotes: rstudio/rmarkdown diff --git a/NEWS.md b/NEWS.md index c4332d63..a935df38 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,27 @@ flexdashboard 0.5.2.9000 =========== +This release is focuses primarily on integration with the new [`{bslib}` package](https://rstudio.github.io/bslib/index.html). As a result, customizing main colors and fonts of `{flexdashboard}` is now much easier, by providing a custom `bslib::bs_theme()` specification to `flex_dashboard`'s `theme` parameter. + +The yaml below demonstrates how to implement a custom dark mode with custom fonts. By default, providing a custom `{bslib}` `theme` in this way upgrades your app from Bootstrap 3 to 4, but if you run into any issues, you can add `version: 3` to the `theme` to use Bootstrap 3 instead of 4. + +````yaml +--- +output: + flexdashboard::flex_dashboard: + theme: + bg: "#101010" + fg: "#FDF7F7" + primary: "#ED79F9" + base_font: !expr bslib::font_google("Prompt") + code_font: !expr bslib::font_google("JetBrains Mono") +--- +```` + +TODO: image? + +Moreover, you can also now theme dashboards in real-time by adding a `runtime: shiny` to the yaml matter, then calling `bslib::bs_themer()` inside a code chunk. + ### Possibly breaking changes * The `smart` argument was removed from `flexdashboard::flex_dashboard` since it was removed in rmarkdown 2.2 (relatedly, we now require rmarkdown 2.2 or higher). (#301) diff --git a/R/dependencies.R b/R/dependencies.R index a0dea7f4..bf44bf2a 100644 --- a/R/dependencies.R +++ b/R/dependencies.R @@ -12,6 +12,8 @@ flexdashboard_dependency <- function(name) { system.file("www", name, package = "flexdashboard") } +# Might have an issue with jQuery 3? +# https://github.com/jmosbech/StickyTableHeaders/pull/157 html_dependency_stickytableheaders <- function() { htmlDependency( "stickytableheaders", diff --git a/R/flex_dashboard.R b/R/flex_dashboard.R index 68840da0..f008910c 100644 --- a/R/flex_dashboard.R +++ b/R/flex_dashboard.R @@ -108,6 +108,7 @@ flex_dashboard <- function(fig_width = 6.0, vertical_layout = c("fill", "scroll"), storyboard = FALSE, theme = "default", + navbar_bg = "primary", highlight = "default", mathjax = "default", extra_dependencies = NULL, @@ -297,54 +298,22 @@ flex_dashboard <- function(fig_width = 6.0, add_graphic("logo", logo) add_graphic("favicon", favicon) - # include flexdashboard.css and flexdashboard.js (but not in devel - # mode, in that case relative filesystem references to - # them are included in the template along with live reload) + # Include flexdashboard.js unless we're in devel mode. + # In that case, relative filesystem references to + # them are included in the template, along with live reload if (devel) { args <- c(args, pandoc_variable_arg("devel", "1")) - dashboardCss <- NULL - dashboardScript <- NULL } else { - if (fill_page) { - fillPageCss <- readLines(resource("fillpage.css")) - } else { - fillPageCss <- NULL - } - - theme <- ifelse(identical(theme, "default"), "bootstrap", theme) - dashboardCss <- c( - '' - ) - - dashboardScript <- c( - '' - ) + dashboardScriptFile <- tempfile(fileext = ".html") + dashboardScript <- c('') + writeLines(dashboardScript, dashboardScriptFile) + includes$before_body <- c(includes$before_body, dashboardScriptFile) } # if there is no fig_mobile height and width then pass the default if (is.null(fig_mobile)) fig_mobile <- default_fig_mobile - # css - if (!is.null(dashboardCss)) { - dashboardCssFile <- tempfile(fileext = "html") - writeLines(dashboardCss, dashboardCssFile) - args <- c(args, pandoc_include_args(in_header = dashboardCssFile)) - } - - # script - if (!is.null(dashboardScript)) { - dashboardScriptFile <- tempfile(fileext = ".html") - writeLines(dashboardScript, dashboardScriptFile) - includes$before_body <- c(includes$before_body, dashboardScriptFile) - } - # dashboard init script dashboardInitScript <- c( '' ) diff --git a/inst/rmarkdown/templates/flex_dashboard/resources/default.html b/inst/rmarkdown/templates/flex_dashboard/resources/default.html index d8bde2c3..6e2f47e9 100644 --- a/inst/rmarkdown/templates/flex_dashboard/resources/default.html +++ b/inst/rmarkdown/templates/flex_dashboard/resources/default.html @@ -99,35 +99,9 @@