How do you change the color of an icon in an R Shiny app?

Viewed 7801

I have a Shiny app that uses a couple icons from the Font Awesome library (built-in) in the UI:

icon("bolt")

icon("compass")

How do I change the color of each icon?

2 Answers

At the beginning of the UI, insert tags$style(".fa-bolt {color:#E87722}") to change the color of the bolt icon. Similarly, add tags$style(".fa-compass {color:#E87722}") to change the color of the compass icon. This will apply the coloring to all bolt icons and compass icons in the app.

You can just use HTML tags instead of using icon()

tags$i(
    class = "fa fa-check-square", 
    style = "color: rgb(0,166,90)"
)

e.g.

library(shiny)

ui <- fluidPage(
    tags$p("icon:"),
    tags$hr(),
    tags$i(
        class = "fa fa-check-square", 
        style = "color: rgb(0,166,90)"
    ),
    icon("check-square")
)

server <- function(input, output, session) {

}

shinyApp(ui, server)
Related