我是
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
主题似乎不起作用。
您需要手动设置原色。这有效:
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)
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)