I'm including a CSS file in a shiny app. I include it in the ui() function prior to including a header that attempts to override the CSS file. Everything I've read indicates that the header CSS declaration should override the CSS file. However it is not overriding it unless I use the "!important" rule after the header CSS declaration. Here's the CSS file (named temp.css):
.btn-default {
color: #ffffff;
background-color: #464545;
border-color: #464545;
}
and here is the R shiny file (named 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 CSS declarations in the header for .btn-default take effect for the actionButton if any of the following are done:
the header declaration is for the button name, using:
HTML("#testButton {
background-color: rgb(40,110,5);
color: rgb(199,207,111);
}"
I've also tried including other selectors in the header CSS, such as .btn
and .action-button
.
Is there something else I should be doing? Is this a shiny problem?
It will work the way you expect it if you put includeCSS("temp.css"),
in your head tag. I am no expert but I think everything in tag$head
is evaluated first and is overwritten by everything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With