How do I use the Bootswatch theme "Minty" in my R Shiny application?

2.1k views Asked by At

I am trying to change the theme of my R Shiny application to "Minty" from the bootswatch theme website: https://bootswatch.com/. However, when I use the shinythemes argument in my code, the theme is not adjusted when I run the application. Any help appreciated.

Update: I was able to get the theme working using the suggestions below, but it doesn't really look similar in terms of color and the navigation bar.

enter image description here

2

There are 2 answers

0
CallumH On

You can set minty as the bootswatch parameter when setting a bs_theme, available in the bslib package.

library(shiny)
library(bslib)

ui <- bootstrapPage(
  theme = bs_theme(version = 5, bootswatch = 'minty'),
    titlePanel("Old Faithful Geyser Data"),
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

server <- function(input, output) {

    output$distPlot <- renderPlot({
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)
        hist(x, breaks = bins, col = 'darkgray', border = 'white',
             xlab = 'Waiting time to next eruption (in mins)',
             main = 'Histogram of waiting times')
    })
}

shinyApp(ui = ui, server = server)
4
Greg On

Minty isn't included in shinythemes so something like fluidPage(theme = shinytheme("minty"), ...) won't work. You can add a theme to your app manually by:

1) Downloading the .css file from bootswatch

2) Placing that .css file in the www/ directory associated with your app as follows:

myapp

|-- server.R

|-- ui.R

|-- www/ > mytheme.css

3) Modifying your ui code to include this:

fluidPage(
  theme = "mytheme.css",
  ...)

Adapted from here (scroll down)