简体   繁体   中英

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

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?

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)"
)

eg

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM