Chrome 某些浏览器会忽略CSS中的颜色值以用于Shiny应用程序

gc0ot86w  于 2023-04-27  发布在  Go
关注(0)|答案(1)|浏览(102)

我们开发了一个新的Shiny应用程序用于研究目的。对于其一般外观和感觉,应用了shinythemes的yeti主题。为了提高可读性,我想将所有地方的字体颜色从深灰色改为黑色。为了实现这一点,我简单地将标签$style添加到UI定义中。令人惊讶的是,此修复在某些浏览器中成功,但并非所有浏览器。结果如下:
Firefox 112.0.1(Windows):改正
Firefox 112.0.1(macOS):改正
Chrome 112.0(Windows):不正确
Chrome 112.0(macOS):改正
Edge 112.0(Windows):不正确
Safari 16.4.1(macOS):改正
我已经检查了Windows上Chrome和Edge中的CSS。yeti.min.css以及scaffolding.less中的灰色值被黑色覆盖。那么为什么这些浏览器最终会忽略它?我如何调整R Shiny代码以在任何浏览器中工作?
补充:事实证明,Chrome和Edge确实会将其他颜色值应用到字体中,例如蓝色。他们只是忽略了黑色,这很奇怪,因为这应该是文本最典型的颜色。
这是一个最小的Shiny应用程序来演示这个问题:

library(shiny)
library(shinythemes)

# Define UI for application that draws a histogram
ui <- fluidPage(theme = shinytheme("yeti"),
                
    tags$style(HTML("
      h2 {
        color: black;
        }
    ")),

    # Application title
    titlePanel("Old Faithful Geyser Data (this title should appear in black)"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

acruukt9

acruukt91#

黑色字体颜色的细微差异可能与CSS无关,而是浏览器渲染文本显示的方式。我检查了其他几个使用黑色字体的网站。Firefox中的运行文本总是比Chrome中的略暗(都是在Windows上)。对于标题,差异是微不足道的,但在放大的屏幕截图中仍然明显。所以我们可以将这个问题视为答案。

相关问题