| 1 |
--- |
| 2 |
title: "Real-time theming with bslib and thematic" |
| 3 |
runtime: shiny |
| 4 |
output: |
| 5 |
html_document: |
| 6 |
code_folding: show |
| 7 |
theme: |
| 8 |
color-contrast-warnings: false |
| 9 |
bg: "#202123" |
| 10 |
fg: "#B8BCC2" |
| 11 |
primary: "#EA80FC" |
| 12 |
secondary: "#00DAC6" |
| 13 |
base_font: |
| 14 |
google: Prompt |
| 15 |
heading_font: |
| 16 |
google: Proza Libre |
| 17 |
--- |
| 18 |
|
| 19 |
```{r setup, include=FALSE} |
| 20 |
bslib::bs_themer() |
| 21 |
if (requireNamespace("thematic")) |
| 22 |
thematic::thematic_rmd(font = "auto") |
| 23 |
``` |
| 24 |
|
| 25 |
## R Markdown |
| 26 |
|
| 27 |
This is an R Markdown document themed with [`{bslib}` package](https://rstudio.github.io/bslib/). `{bslib}` makes it easy to customize the main colors and fonts of a `html_document`, [`flexdashboard::flex_dashboard`](https://flexdashboard-pkg.netlify.app/articles/articles/theme.html), [shiny::fluidPage()](https://shiny.rstudio.com/reference/shiny/latest/fluidPage.html), or more generally any website that uses [Bootstrap](https://getbootstrap.com/) for styling. The `theme` parameter in the yaml front-matter of this Rmd document describes a [`bslib::bs_theme()`](https://rstudio.github.io/bslib/reference/bs_theme.html) object, which provides access to 100s of [theming options](https://rstudio.github.io/bslib/articles/bs4-variables.html) (via its `...` argument) in addition to the main options demonstrated here (e.g., `bg`, `fg`, `primary`, etc). |
| 28 |
|
| 29 |
This document also uses [`runtime: shiny`](https://shiny.rstudio.com/articles/interactive-docs.html) to call [`bslib::bs_themer()`](https://rstudio.github.io/bslib/reference/run_with_themer.html) which overlays a "real-time" theming widget for interactively customizing main theme settings. |
| 30 |
|
| 31 |
## Themed Plots {.tabset .tabset-pills} |
| 32 |
|
| 33 |
When running this document with [`{thematic}`](https://rstudio.github.io/thematic/) installed, the `thematic::thematic_rmd(font = "auto")` effectively translates `theme` (CSS) settings to new global theming defaults for `{ggplot2}`, `{lattice}`, and `{base}` R graphics: |
| 34 |
|
| 35 |
### ggplot2 |
| 36 |
|
| 37 |
```{r, message = FALSE} |
| 38 |
library(ggplot2) |
| 39 |
|
| 40 |
renderPlot({ |
| 41 |
ggplot(mpg, aes(displ, hwy)) + |
| 42 |
geom_point() + geom_smooth() |
| 43 |
}) |
| 44 |
``` |
| 45 |
|
| 46 |
### lattice |
| 47 |
|
| 48 |
```{r} |
| 49 |
renderPlot({ |
| 50 |
lattice::show.settings() |
| 51 |
}) |
| 52 |
``` |
| 53 |
|
| 54 |
### base |
| 55 |
|
| 56 |
```{r} |
| 57 |
renderPlot({ |
| 58 |
plot(pressure, col = thematic::thematic_get_option("accent")) |
| 59 |
}) |
| 60 |
``` |