我在一个shiny app中包含了一个CSS文件。在包含尝试覆盖CSS文件的标头之前,我在ui()函数中包含了它。我阅读的所有内容都表明,标头CSS声明应该覆盖CSS文件。然而,除非我在标头CSS声明后使用"!important"规则,否则它不会覆盖它。这是CSS文件(命名为temp.css):
.btn-default {
color: #ffffff;
background-color: #464545;
border-color: #464545;
}
以下是 R Shiny 文件(命名为 app.R):
library(shiny)
shinyApp(
ui <- shinyUI(
fluidPage(
# # Set up the basic CSS styling.
includeCSS("temp.css"),
# HTML header with style specifications.
tags$head(
tags$style(
# Colorize the actionButton.
HTML(".btn-default {
background-color: rgb(40,110,5);
color: rgb(199,207,111);
}"
)
)
),
fluidRow(
sidebarPanel(
# Insert a button.
actionButton(
inputId = "testButton",
label = "Click Here"
)
)
)
)
),
server <- shinyServer(function(input, output, session) {
})
)
- the !important rule follows the CSS declarations in the header;
- the temp.css file is not included; or
the header declaration is for the button name, using:
HTML("#testButton { background-color: rgb(40,110,5); color: rgb(199,207,111); }"
.btn
和.action-button
。我应该做些什么?这是一个闪亮的问题吗?
includeCSS()
行移动到了tags$head()
和tags$style()
行之间,现在一切都按预期工作了。 - datatoolbox!important
标签的方法是将需要覆盖!important
标签的标签粘贴在多个tags$style(HTML(...))
行中。 - scabecks