Learn R Programming

⚠️There's a newer version (0.8.0) of this package.Take me there.

bslib

The bslib R package provides tools for customizing Bootstrap themes directly from R, making it much easier to customize the appearance of Shiny apps & R Markdown documents. bslib’s primary goals are:

Installation

Install the stable release of bslib on CRAN:

install.packages("bslib")

Usage with Shiny requires version 1.6 or higher:

install.packages("shiny")

Usage with R Markdown requires version 2.7 or higher:

install.packages("rmarkdown")

Basic usage

bslib is designed for use with any Shiny or R Markdown project that uses Bootstrap. In most cases, you can identify a project that uses Bootstrap when the relevant page constructor has a theme parameter. For example, most Shiny page layout functions (e.g., shiny::navbarPage()) and some popular R Markdown formats (e.g., rmarkdown::html_document) all have a theme parameter.

To use bslib in Shiny, provide a bs_theme() object to the theme parameter; and in R Markdown, provide bs_theme() parameters to theme. For example, here’s a way to upgrade Shiny (left) and R Markdown (right) from Bootstrap 3 to 4:

library(shiny)
ui <- navbarPage(
  theme = bs_theme(version = 4),
  ...
)
shinyApp(ui, function(...) {})
---
output:
  html_document:
    theme:
      version: 4
---

See the Get Started article to learn more about Bootstrap versions, pre-packaged Bootswatch themes, (real-time) custom theming, and more.

To get started more quickly, choose a relevant R Markdown template from inside RStudio by going to File -> New File -> R Markdown -> From Template:

Getting help

There are two main places to get help with bslib:

  • The RStudio community is a friendly place to ask any questions (be sure to add a bslib tag when creating a topic).

  • Stack Overflow is a great source of answers to common bslib questions. It is also a great place to get help, once you have created a reproducible example that illustrates your problem. Use the tags [r][bslib] if you ask a question. Add the tag [bslib] if you are using a Shiny runtime.

Code of Conduct

Please note that the bslib project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('bslib')

Monthly Downloads

820,225

Version

0.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Carson Sievert

Last Published

September 2nd, 2021

Functions in bslib (0.3.0)

bs_get_variables

Retrieve Sass variable values from the current theme
bs_dependency

Themeable HTML components
bs_theme_dependencies

Compile Bootstrap Sass with (optional) theming
bootswatch_themes

Obtain a list of all available bootswatch themes.
bs_remove

Remove or retrieve Sass code from a theme
bs_global_theme

Global theming
bs_current_theme

Obtain the currently active theme at render time
bs_theme

Create a Bootstrap theme
bs_theme_preview

Preview the currently set theme
bs_add_variables

Add low-level theming customizations
navs_tab

Navigation containers
font_face

Helpers for importing web fonts
bs_theme_new

Deprecated functions
versions

Available Bootstrap versions
nav_prepend

Append or prepend nav item to a dropdown menu
nav_select

Dynamically update nav containers
page

Create a Bootstrap page
theme_version

Obtain a theme's Bootstrap version
theme_bootswatch

Obtain a theme's Bootswatch theme name
print.bslib_fragment

Make HTML browsable by default
nav

Navigation items
run_with_themer

Theme customization UI
precompiled_css_path

Get the path to a precompiled CSS file