Skip to content

Commit

Permalink
added bs4Dash_theme
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jun 17, 2024
1 parent f2fad54 commit a6980dc
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 139 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
Imports:
sass,
bslib,
htmltools,
shiny,
rstudioapi
rstudioapi,
sass,
shiny
Suggests:
shinyWidgets,
shinydashboard,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions R/bs4Dash_theme.R
Original file line number Diff line number Diff line change
@@ -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)
}
21 changes: 17 additions & 4 deletions R/use_theme.R
Original file line number Diff line number Diff line change
@@ -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()) {
Expand Down Expand Up @@ -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",
Expand Down
125 changes: 58 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down Expand Up @@ -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")`.




57 changes: 57 additions & 0 deletions examples/bs4Dash_theme-ex.R
Original file line number Diff line number Diff line change
@@ -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(...) {}
)
}

2 changes: 1 addition & 1 deletion inst/assets/AdminLTE-3.1.0/_info-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions inst/assets/AdminLTE-3.1.0/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit a6980dc

Please sign in to comment.