R bslib更改navbar颜色引导版本5

czq61nw1  于 2023-09-27  发布在  其他
关注(0)|答案(2)|浏览(92)

为什么在shiny(版本1.6.0.9022)中更改导航栏颜色不适用于BS版本4和5?
可重复的示例:
app.R

library(shiny)
library(bslib)

theme_test <- bs_theme(version = 5,
                       primary = "#d83e3e") %>%
bs_add_rules(sass::sass_file("custom.scss"))

ui <- navbarPage(title = "Test", theme = theme_test)

server <- function(input, output) {}

shinyApp(ui, server)

custom.scss

.navbar { 
    background-color: $primary;
    color: $primary;
}

运行

library(shiny)
runApp("FOLDERNAME")
ztigrdn8

ztigrdn81#

经过一番折腾,我找到了正确的css/sass:

.bg-light, .navbar-default {
    background-color: $primary !important;
}
cgh8pdjw

cgh8pdjw2#

可能值得考虑的是,正确的类可能会根据主题和其他设置而变化。例如,为了正确使用sandstone,我使用了以下代码:

theme = bslib::bs_theme(
      version = "5",
      preset = "sandstone", 
    ) %>%
      bslib::bs_add_rules(rules = "
.navbar.navbar-inverse {
   background-color: $dark !important;
}")

相关问题