确定的前景 /背景颜色在BSLIB应用程序中具有深色 /光模式

问题描述 投票:0回答:1
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:

r bslib
1个回答
0
投票

bslib


最新问题
© www.soinside.com 2019 - 2024. All rights reserved.