How to change background color and text color of a titlePanel in R Shiny?

I’m having trouble changing the background color and text color in my Shiny dashboard and the videos and sites that I’ve looked at have been no help as what they say to do is giving me an error. My code is:

ui <- fluidPage(
  titlePanel(HTML("<center>This Is My Title</center>"),
             tags$style(
                background-color: "blue",
                color: "white")
))

As you can see, I am trying to make the text color white and the background for only the title to be blue. If anyone can help that would be much appreciated.

>Solution :

titlePanel("This is my title")
tags$style(HTML("
    body {
            background-color: Black;
            color: white;
            }"))

You can use titlePanel to set your title in shiny instead of wrapping in HTML, and then for the CSS, it needs to be completely wrapped by HTML() and Quotes for it to work.

Leave a Reply