bslib theme not coloring page_navbar as expected

297 Views Asked by At

I'm new to bslib and was excited about some of the style options it presents, but I can't seem to get them working right. I was interested to use the pulse bootswatch for the purple (https://bootswatch.com/pulse/), but I'm not seeing it ...

library(shiny)
library(bslib)

ui <- page_navbar(
    title = "why is the background here not purple?",
    theme = bs_theme(bootswatch = "pulse")
)

server <- function(input, output, session) {
    bs_themer()
}

shinyApp(ui = ui, server = server)

Using the bs_themer in the top right of the app seems to give inconsistent results, but other bootswatches do sometimes seem to use the primary color as the header background as expected, but the pulse theme doesn't seem to work.

2

There are 2 best solutions below

3
Jan On BEST ANSWER

You need to set the primary color manually. This works:

library(shiny)
library(bslib)

ui <- page_navbar(
    title = "background is now purple",
    theme = bs_theme(bootswatch = "pulse") |>
        bslib::bs_add_rules(
            rules = "
                    .navbar.navbar-default {
                        background-color: $primary !important;
                    }
                    "
        )
)

server <- function(input, output, session) {
}

shinyApp(ui = ui, server = server)

enter image description here

0
carverd On

There is a bg argument within the page_navbar() function. This seems to be the only color related argument.

You can use this to set the nav bar color with a color string ex("purple' or "#44155f")

library(shiny)
library(bslib)

ui <- page_navbar(
  title = "why is the background here not purple?",
  theme = bs_theme(bootswatch = "pulse"),
  bg = "purple"
)

server <- function(input, output, session) {
  bs_themer()
}

shinyApp(ui = ui, server = server)