fg
和
bg
选项设置为par()
。
快速搜索提出功能
bs_current_theme
和
bs_get_variables
::
current_theme <- bslib::bs_current_theme()
bg <- bslib::bs_get_variables(current_theme, "body-bg")[["body-bg"]]
,但是,在调用bg
之后,
toggle_dark_mode()
的值似乎没有变化。这是一个示例应用程序,它每次按下深色/光模式按钮时打印
bg
:ui <- bslib::page_navbar(
title = "Dark Mode Demo",
theme = bslib::bs_theme(version=5),
bslib::nav_panel(
title = "Base Graphics",
bslib::card(
bslib::card_header("Mosaic"),
shiny::plotOutput("base_mosaic")
)
),
bslib::nav_spacer(),
bslib::nav_item(
bslib::input_dark_mode(id = "theme_toggle", mode = "light")
)
)
server <- function(input, output, session) {
# dark / light mode
shiny::observeEvent(input$theme_toggle, {
bslib::toggle_dark_mode(mode=input$theme_toggle)
current_theme <- bslib::bs_current_theme()
message("bg=", bslib::bs_get_variables(current_theme, "body-bg")[["body-bg"]])
par(bg = bslib::bs_get_variables(current_theme, "body-bg")[["body-bg"]])
})
output$base_mosaic <- shiny::renderPlot({
plot(1:10)
})
}
shiny::shinyApp(ui, server)
确定当前背景和前景(=文本)颜色的最佳方法是什么?
custom messagehandler:它获取Bootstrap变量的当前值,并将其发送到Shinny: