bslib 主题未按预期着色 page_navbar

问题描述 投票:0回答:2

我是

bslib
的新手,对它提供的一些样式选项感到兴奋,但我似乎无法让它们正常工作。我有兴趣使用紫色的
pulse
bootswatch (https://bootswatch.com/pulse/),但我没有看到它......

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)

使用应用程序右上角的

bs_themer
似乎会给出不一致的结果,但其他 bootswatches 有时似乎确实按预期使用原色作为标题背景,但
pulse
主题似乎不起作用。

r shiny sass bootswatch bslib
2个回答
1
投票

您需要手动设置原色。这有效:

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)


0
投票

bg
函数中有一个
page_navbar()
参数。这似乎是唯一与颜色相关的论点。

您可以使用它通过颜色字符串 ex("purple' 或 "#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)
© www.soinside.com 2019 - 2024. All rights reserved.