Search code examples
rshinyiconsshinydashboardflexdashboard

Add rho as icon in valueBox


Can I add a rho (Greek letter small) as an icon to a value box in RShiny? For example, with the following code snippet, I have created a value box that has the € symbol as an icon:

valueBox(winterMean, subtitle = "Mean Winter", color = "black", icon = icon("euro-sign"))

This gives the following value box:

enter image description here

How can I replace the € symbol by a small rho?


Solution

  • We can add custom Greek letters using Unicode Character "ρ" (U+03C1) through custom css, see example:

    Using flexdashboard:

    Our example rmd file:

    ---
    title: "My Rho"
    output: 
      flexdashboard::flex_dashboard:
        css: styles.css
    ---
    
    ```{r}
    library(flexdashboard)
    
    valueBox(42, caption = "My Rho", icon = "fa-rho")
    ```
    

    And additional styles.css file:

    .fa-rho:before {
        font-weight: 700;
        content: '\03c1';
    }
    

    Output:

    enter image description here

    Note: For my test I kept css file in the same folder as rmd file, but it could be in any subfolder, then we need to define the full path in rmd, e.g.: resources/css/styles.css.


    Using shinydashboard

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
        includeCSS("styles.css"),
        valueBox(42, "My Rho", icon = icon("rho")),
      )
    )
    
    server <- function(input, output) { }
    
    shinyApp(ui, server)
    

    Output:

    enter image description here