Reputation: 905
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.
Upvotes: 5
Views: 2615
Reputation: 779
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)
Upvotes: 1
Reputation: 3660
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)
Upvotes: 4