Last active
February 1, 2021 03:08
-
-
Save homerhanumat/bc7ac9cbf93b24552134 to your computer and use it in GitHub Desktop.
Shiny dashboard with yellow sidebar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(shinydashboard) | |
ui <- dashboardPage( | |
dashboardHeader(), | |
dashboardSidebar(), | |
dashboardBody(), | |
tags$head(tags$style(HTML(" | |
.skin-blue .main-sidebar { | |
background-color: yellow; | |
}"))) | |
) | |
server <- function(input, output) { } | |
shinyApp(ui, server) |
@Fahim-Ahmad, the default skin for shinydashboard
is blue, so when no skin is specied in the R code, the <aside>
tag that constitutes the sidebar gets CSS classes that include "skin-blue"
. So when you add your custom styling, you need to specify .skin-blue
in the CSS rule.
If you change the theme to red then the <aside>
tag inherits class "skin-red"
, so the custom styling rule no longer applies to it.
The fix is simple, just modify the custom styling:
u <- dashboardPage(skin = "red",
dashboardHeader(),
dashboardSidebar(),
dashboardBody(),
tags$head(
tags$style(HTML(".skin-red .main-sidebar {background-color: yellow;}"))
)
)
s <- function(input, output) { }
shinyApp(u, s)
In my code I specified the .skin-*
class in the custom styling, so that my rule for background-color would over-ride the CSS rules provided by shinydashboard
. Another solution would be to use !important
, like this:
u <- dashboardPage(skin = "red",
dashboardHeader(),
dashboardSidebar(),
dashboardBody(),
tags$head(
tags$style(HTML(".main-sidebar {background-color: yellow !important;}"))
)
)
s <- function(input, output) { }
shinyApp(u, s)
Thank you a lot!
I didn't know about !important
. It is excellent.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, @homerhanumat.
Do you know why the above chunk of codes does not work when changing the header color?