CRAN status Lifecycle: experimental R build status

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 5:

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

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:

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.