diff --git a/DESCRIPTION b/DESCRIPTION index 185d921..c9bcbef 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,10 +19,11 @@ License: GPL-3 Encoding: UTF-8 LazyData: true Imports: - sass, + bslib, htmltools, - shiny, - rstudioapi + rstudioapi, + sass, + shiny Suggests: shinyWidgets, shinydashboard, diff --git a/NAMESPACE b/NAMESPACE index 4d514f9..e5347e0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(adminlte_color) export(adminlte_global) export(adminlte_sidebar) export(adminlte_vars) +export(bs4Dash_theme) export(bs4dash_button) export(bs4dash_color) export(bs4dash_font) @@ -44,9 +45,14 @@ export(use_googlefont) export(use_pretty) export(use_theme) export(use_vars_template) +importFrom(bslib,bs_add_rules) +importFrom(bslib,bs_add_variables) +importFrom(bslib,bs_theme) +importFrom(bslib,bs_theme_dependencies) importFrom(htmltools,HTML) importFrom(htmltools,htmlDependency) importFrom(htmltools,singleton) +importFrom(htmltools,tagList) importFrom(htmltools,tags) importFrom(rstudioapi,isAvailable) importFrom(rstudioapi,navigateToFile) diff --git a/R/bs4Dash_theme.R b/R/bs4Dash_theme.R new file mode 100644 index 0000000..0048f51 --- /dev/null +++ b/R/bs4Dash_theme.R @@ -0,0 +1,40 @@ + +#' Create a theme for bs4Dash +#' +#' @inheritParams bslib::bs_theme +#' @param ... Additional AdminLTE variables. +#' +#' @return Returns a [sass::sass_bundle()] (list-like) object. +#' @export +#' +#' @importFrom bslib bs_theme bs_add_variables bs_add_rules bs_theme_dependencies +#' +#' @example examples/bs4Dash_theme-ex.R +bs4Dash_theme <- function(primary = NULL, + secondary = NULL, + success = NULL, + info = NULL, + warning = NULL, + danger = NULL, + ...) { + theme <- bs_theme( + version = 4, + preset = "bootstrap", + primary = primary, + secondary = secondary, + success = success, + info = info, + warning = warning, + danger = danger + ) + theme <- bs_add_variables( + theme = theme, + ... + ) + theme <- bs_add_rules( + theme = theme, + adminlte3_scss() + ) + class(theme) <- c(class(theme), "bs4Dash_theme") + return(theme) +} diff --git a/R/use_theme.R b/R/use_theme.R index 6edc315..48163db 100644 --- a/R/use_theme.R +++ b/R/use_theme.R @@ -1,14 +1,15 @@ #' Use a CSS theme in Shiny application #' -#' @param theme Either a path to CSS file (if in \code{www/} folder, -#' do not include \code{www/} in path), or a theme generated with -#' \code{\link{create_theme}} and argument \code{output_file = NULL}. +#' @param theme Either a path to CSS file (if in `www/` folder, +#' do not include `www/` in path), or a theme generated with +#' [create_theme()] and argument `output_file = NULL` or [bs4Dash_theme()]. #' #' @return HTML tags to be included in a UI definition. #' @export #' -#' @importFrom htmltools singleton tags HTML +#' @importFrom htmltools singleton tags HTML htmlDependency tagList +#' @importFrom bslib bs_theme_dependencies #' #' @examples #' if (interactive()) { @@ -50,6 +51,18 @@ #' shinyApp(ui, server) #' } use_theme <- function(theme) { + if (inherits(theme, what = "bs4Dash_theme")) { + return(tagList( + bs_theme_dependencies(theme), + htmlDependency( + name = "AdminLTE3", + version = "3.1.0.9000", + src = c(file = "AdminLTE3-3.1.0"), + script = "adminlte.min.js", + package = "bs4Dash" + ) + )) + } if (inherits(theme, what = "css")) { tags$head(tags$style( id = "fresh-theme", diff --git a/README.md b/README.md index 432d7be..ac787b6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,64 @@ You can install the development version of fresh from GitHub with: remotes::install_github("dreamRs/fresh") ``` + + +## bs4Dash + +Create a theme to personalize your [{bs4Dash}](https://github.com/RinteRface/bs4Dash) applications: + +![](man/figures/bs4dash.png) + +Create the theme: + +```r +bs4DashTheme <- bs4Dash_theme( + primary = "#5E81AC", + secondary = "#B48EAD", + success = "#A3BE8C", + danger = "#BF616A", + "sidebar-light-bg" = "#3B4252", + "sidebar-light-color" = "#E5E9F0", + "main-bg" = "#2E3440", + "body-color" = "#ECEFF4", + "card-bg" = "#4C566A", # bs4Card() background + "white" = "#E5E9F0", + "info-box-bg" = "#4C566A", # bs4InfoBox() background + dark = "#272c30", # bs4DashNavbar(status = "dark") background, + "gray-600" = "#FFF" +) +``` + +Use your theme: + +```r +bs4DashPage( + title = "bs4Dash custom theme", + navbar = bs4DashNavbar(skin = "light"), + sidebar = bs4DashSidebar( + title = "bs4Dash custom theme", + skin = "light", + + # ... + + ), + body = bs4DashBody( + + use_theme(bs4DashTheme), # <-- use the theme + + # ... + + ) +) +``` + + +See more information here: [Variables for {bs4dash}](https://dreamrs.github.io/fresh/articles/vars-bs4dash.html) or in R console: `vignette("vars-bs4dash", package = "fresh")`. + + + + + ## shiny Create new themes to use in shiny applications with `fluidPage` or `navbarPage`. From the default theme : @@ -140,72 +198,5 @@ See more information here: [Variables for {shinydashboard}](https://dreamrs.gith -## bs4Dash - -Create a theme to personalize your [{bs4Dash}](https://github.com/RinteRface/bs4Dash) applications: - -![](man/figures/bs4dash.png) - -Create the theme: - -```r -mytheme <- create_theme( - bs4dash_vars( - navbar_light_color = "#bec5cb", - navbar_light_active_color = "#FFF", - navbar_light_hover_color = "#FFF" - ), - bs4dash_yiq( - contrasted_threshold = 10, - text_dark = "#FFF", - text_light = "#272c30" - ), - bs4dash_layout( - main_bg = "#353c42" - ), - bs4dash_sidebar_light( - bg = "#272c30", - color = "#bec5cb", - hover_color = "#FFF", - submenu_bg = "#272c30", - submenu_color = "#FFF", - submenu_hover_color = "#FFF" - ), - bs4dash_status( - primary = "#5E81AC", danger = "#BF616A", light = "#272c30" - ), - bs4dash_color( - gray_900 = "#FFF" - ) -) -``` - -Use your theme: - -```r -bs4DashPage( - title = "bs4Dash custom theme", - navbar = bs4DashNavbar(skin = "light"), - sidebar = bs4DashSidebar( - title = "bs4Dash custom theme", - skin = "light", - - # ... - - ), - body = bs4DashBody( - - use_theme(mytheme), # <-- use the theme - - # ... - - ) -) -``` - - -See more information here: [Variables for {bs4dash}](https://dreamrs.github.io/fresh/articles/vars-bs4dash.html) or in R console: `vignette("vars-bs4dash", package = "fresh")`. - - diff --git a/examples/bs4Dash_theme-ex.R b/examples/bs4Dash_theme-ex.R new file mode 100644 index 0000000..0d28fc0 --- /dev/null +++ b/examples/bs4Dash_theme-ex.R @@ -0,0 +1,57 @@ + + +library(shiny) +library(bs4Dash) +library(fresh) + +ui <- dashboardPage( + options = NULL, + header = dashboardHeader( + status = "primary", + title = dashboardBrand( + title = "My dashboard", + color = "primary", + href = "https://adminlte.io/themes/v3", + image = "https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png" + ) + ), + sidebar = dashboardSidebar( + sidebarMenu( + menuItem( + text = "Tab 1", + tabName = "tab1", + icon = icon("van-shuttle") + ), + menuItem( + text = "Tab 2", + tabName = "tab2", + icon = icon("shuttle-space") + ) + ) + ), + body = dashboardBody( + use_theme( + bs4Dash_theme( + primary = "purple", + success = "yellow", + danger = "pink", + "sidebar-light-bg" = "#C38AFF", + "main-bg" = "#D9BBFF" + ) + ), + box(status = "danger", solidHeader = TRUE, title = "Title", "Content"), + box(status = "primary", solidHeader = TRUE, title = "Title", "Content"), + box(status = "success", solidHeader = TRUE, title = "Title", "Content") + ), + controlbar = dashboardControlbar(), + title = "DashboardPage" +) + + +if (interactive()) { + shinyApp( + ui = ui, + server = function(...) {} + ) +} + diff --git a/inst/assets/AdminLTE-3.1.0/_info-box.scss b/inst/assets/AdminLTE-3.1.0/_info-box.scss index 6ae9a6c..5c1da6e 100644 --- a/inst/assets/AdminLTE-3.1.0/_info-box.scss +++ b/inst/assets/AdminLTE-3.1.0/_info-box.scss @@ -6,7 +6,7 @@ @include box-shadow($card-shadow); @include border-radius($border-radius); - background-color: $white; + background-color: $info-box-bg; display: flex; margin-bottom: map-get($spacers, 3); min-height: 80px; diff --git a/inst/assets/AdminLTE-3.1.0/_variables.scss b/inst/assets/AdminLTE-3.1.0/_variables.scss index 345b13f..71a606c 100644 --- a/inst/assets/AdminLTE-3.1.0/_variables.scss +++ b/inst/assets/AdminLTE-3.1.0/_variables.scss @@ -52,6 +52,9 @@ $main-bg: #f4f6f9 !default; $dark-main-bg: lighten($dark, 7.5%) !important; +// info-box (custom var) +$info-box-bg: $white !default; + // Content padding $content-padding-y: 0 !default; $content-padding-x: $navbar-padding-x !default; diff --git a/inst/examples/bs4Dash/app.R b/inst/examples/bs4Dash/app.R index f2bb5c1..9174c9b 100644 --- a/inst/examples/bs4Dash/app.R +++ b/inst/examples/bs4Dash/app.R @@ -20,9 +20,7 @@ library(fresh) # Theme ------------------------------------------------------------------- -bs4DashTheme <- create_theme( - bs4dash_status(primary = "#FFFF00", danger = "#3ADF00") -) +bs4DashTheme <- bs4Dash_theme(primary = "#FFFF00", danger = "#3ADF00") @@ -31,7 +29,7 @@ bs4DashTheme <- create_theme( ui <- bs4DashPage( title = "bs4Dash Custom Theme", - navbar = bs4DashNavbar(skin = "light"), + header = bs4DashNavbar(skin = "light"), sidebar = bs4DashSidebar( title = "bs4Dash Custom Theme", skin = "light", @@ -60,24 +58,24 @@ ui <- bs4DashPage( bs4ValueBox( value = 150, subtitle = "ValueBox with primary status", - status = "primary", - icon = "shopping-cart", + color = "primary", + icon = icon("shopping-cart"), href = "#", width = 4 ), bs4ValueBox( value = 150, subtitle = "ValueBox with secondary status", - status = "secondary", - icon = "shopping-cart", + color = "secondary", + icon = icon("shopping-cart"), href = "#", width = 4 ), bs4ValueBox( value = "53%", subtitle = "ValueBox with danger status", - status = "danger", - icon = "cogs", + color = "danger", + icon = icon("cogs"), footer = "Hello World", width = 4 ) @@ -86,22 +84,22 @@ ui <- bs4DashPage( bs4ValueBox( value = "44", subtitle = "ValueBox with warning status", - status = "warning", - icon = "sliders", + color = "warning", + icon = icon("sliders"), width = 4 ), bs4ValueBox( value = "44", subtitle = "ValueBox with info status", - status = "info", - icon = "sliders", + color = "info", + icon = icon("sliders"), width = 4 ), bs4ValueBox( value = "44", subtitle = "ValueBox with success status", - status = "success", - icon = "sliders", + color = "success", + icon = icon("sliders"), width = 4 ) ), @@ -110,25 +108,24 @@ ui <- bs4DashPage( bs4InfoBox( value = 150, title = "InfoBox with primary status", - status = "primary", - icon = "shopping-cart", + color = "primary", + icon = icon("shopping-cart"), href = "#", width = 4 ), bs4InfoBox( value = 150, title = "InfoBox with secondary status", - status = "secondary", - icon = "shopping-cart", + color = "secondary", + icon = icon("shopping-cart"), href = "#", width = 4 ), bs4InfoBox( value = "53%", title = "InfoBox with danger status", - status = "danger", - icon = "cogs", - footer = "Hello World", + color = "danger", + icon = icon("cogs"), width = 4 ) ), @@ -136,22 +133,22 @@ ui <- bs4DashPage( bs4InfoBox( value = "44", title = "InfoBox with warning status", - status = "warning", - icon = "sliders", + color = "warning", + icon = icon("sliders"), width = 4 ), bs4InfoBox( value = "44", title = "InfoBox with info status", - status = "info", - icon = "sliders", + color = "info", + icon = icon("sliders"), width = 4 ), bs4InfoBox( value = "44", title = "InfoBox with success status", - status = "success", - icon = "sliders", + color = "success", + icon = icon("sliders"), width = 4 ) ), diff --git a/inst/examples/bs4Dash/dark-mode.R b/inst/examples/bs4Dash/dark-mode.R index f974437..eb931da 100644 --- a/inst/examples/bs4Dash/dark-mode.R +++ b/inst/examples/bs4Dash/dark-mode.R @@ -21,35 +21,20 @@ library(fresh) # Theme ------------------------------------------------------------------- library(fresh) -bs4DashTheme <- create_theme( - bs4dash_vars( - # white = "#bec5cb", - "body-color" = "#FFF", - navbar_dark_color = "#bec5cb", - navbar_dark_active_color = "#FFF", - navbar_dark_hover_color = "#FFF" - ), - bs4dash_yiq( - contrasted_threshold = 10, - text_dark = "#FFF", - text_light = "#272c30" - ), - bs4dash_layout(main_bg = "#353c42"), - bs4dash_sidebar_dark( - bg = "#272c30", - color = "#bec5cb", - hover_color = "#FFF", - - submenu_bg = "#272c30", - submenu_color = "#FFF", - submenu_hover_color = "#FFF" - ), - bs4dash_status( - dark = "#272c30", - primary = "#5E81AC", - danger = "#BF616A" - ), - bs4dash_color(gray_900 = "#FFF", white = "#bec5cb") +bs4DashTheme <- bs4Dash_theme( + primary = "#5E81AC", + secondary = "#B48EAD", + success = "#A3BE8C", + danger = "#BF616A", + "sidebar-light-bg" = "#3B4252", + "sidebar-light-color" = "#E5E9F0", + "main-bg" = "#2E3440", + "body-color" = "#ECEFF4", + "card-bg" = "#4C566A", # bs4Card() background + "white" = "#E5E9F0", + "info-box-bg" = "#4C566A", # bs4InfoBox() background + dark = "#272c30", # bs4DashNavbar(status = "dark") background, + "gray-600" = "#FFF" ) @@ -58,15 +43,16 @@ bs4DashTheme <- create_theme( ui <- bs4DashPage( - title = "bs4Dash Dark Mode", + dark = NULL, + title = "bs4Dash Custom Dark Mode", # sidebar_collapsed = FALSE, - header = bs4DashNavbar(skin = "dark", status = "gray-dark"), + header = bs4DashNavbar(status = "dark"), controlbar = bs4DashControlbar( skin = "dark", "This is the control bar" ), sidebar = bs4DashSidebar( - title = "bs4Dash Dark Mode", + title = "bs4Dash Custom Dark Mode", skin = "dark", bs4SidebarMenu( bs4SidebarHeader("Menu:"), diff --git a/man/bs4Dash_theme.Rd b/man/bs4Dash_theme.Rd new file mode 100644 index 0000000..3195d6f --- /dev/null +++ b/man/bs4Dash_theme.Rd @@ -0,0 +1,102 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bs4Dash_theme.R +\name{bs4Dash_theme} +\alias{bs4Dash_theme} +\title{Create a theme for bs4Dash} +\usage{ +bs4Dash_theme( + primary = NULL, + secondary = NULL, + success = NULL, + info = NULL, + warning = NULL, + danger = NULL, + ... +) +} +\arguments{ +\item{primary}{A color to be used for hyperlinks, to indicate primary/default +actions, and to show active selection state in some Bootstrap components. +Generally a bold, saturated color that contrasts with the theme's base +colors.} + +\item{secondary}{A color for components and messages that don't need to stand +out. (Not supported in Bootstrap 3.)} + +\item{success}{A color for messages that indicate an operation has succeeded. +Typically green.} + +\item{info}{A color for messages that are informative but not critical. +Typically a shade of blue-green.} + +\item{warning}{A color for warning messages. Typically yellow.} + +\item{danger}{A color for errors. Typically red.} + +\item{...}{Additional AdminLTE variables.} +} +\value{ +Returns a \code{\link[sass:sass_layer]{sass::sass_bundle()}} (list-like) object. +} +\description{ +Create a theme for bs4Dash +} +\examples{ + + +library(shiny) +library(bs4Dash) +library(fresh) + +ui <- dashboardPage( + options = NULL, + header = dashboardHeader( + status = "primary", + title = dashboardBrand( + title = "My dashboard", + color = "primary", + href = "https://adminlte.io/themes/v3", + image = "https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png" + ) + ), + sidebar = dashboardSidebar( + sidebarMenu( + menuItem( + text = "Tab 1", + tabName = "tab1", + icon = icon("van-shuttle") + ), + menuItem( + text = "Tab 2", + tabName = "tab2", + icon = icon("shuttle-space") + ) + ) + ), + body = dashboardBody( + use_theme( + bs4Dash_theme( + primary = "purple", + success = "yellow", + danger = "pink", + "sidebar-light-bg" = "#C38AFF", + "main-bg" = "#D9BBFF" + ) + ), + box(status = "danger", solidHeader = TRUE, title = "Title", "Content"), + box(status = "primary", solidHeader = TRUE, title = "Title", "Content"), + box(status = "success", solidHeader = TRUE, title = "Title", "Content") + ), + controlbar = dashboardControlbar(), + title = "DashboardPage" +) + + +if (interactive()) { + shinyApp( + ui = ui, + server = function(...) {} + ) +} + +} diff --git a/man/use_theme.Rd b/man/use_theme.Rd index 4fc1441..cc99d0c 100644 --- a/man/use_theme.Rd +++ b/man/use_theme.Rd @@ -7,9 +7,9 @@ use_theme(theme) } \arguments{ -\item{theme}{Either a path to CSS file (if in \code{www/} folder, -do not include \code{www/} in path), or a theme generated with -\code{\link{create_theme}} and argument \code{output_file = NULL}.} +\item{theme}{Either a path to CSS file (if in \verb{www/} folder, +do not include \verb{www/} in path), or a theme generated with +\code{\link[=create_theme]{create_theme()}} and argument \code{output_file = NULL} or \code{\link[=bs4Dash_theme]{bs4Dash_theme()}}.} } \value{ HTML tags to be included in a UI definition.