This article describes how to use R code to create icons by passing HTML code to a function rhtmlMetro::Box within R to render the HTML code. This can use R code to show an icon, such as an arrow, in your report:
Requirements
- A Displayr document.
- HTML code referencing the icon. These examples use free icons created by Font Awesome. You can find code for more free icons in their free icon gallery. The Noun Project is another source of many icons you can download.
Method
- From the toolbar, go to Calculation > Custom Code.
- Paste the following code into the R CODE area in the object inspector and click Calculate.
#create HTML to load the Font Awesome css
fontawesome_css <- '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">'
#create HTML to reference the icon in an iframe
icon <- '<font color="red" style="font-size: 50pt"><i class="fas fa-arrow-down"></i></font>'
#use the rhtmlMetro Box function to render the HTML code you created
rhtmlMetro::Box(text = paste(fontawesome_css, icon), text.as.html = TRUE)
This will create a red arrow icon on the page:
[OPTIONAL] If you would like to change the color of the arrow, font size, or up/down orientation, you can update "red", "font-size: 50 pt", and "fas fa-arrow-down" to the desired color, font size, and orientation (ie, "fas fa-arrow-up") in the first line of code above:
Next
How to Change Font Color Based on Data Using R
How to Create a Single Icon Pictograph
How to Switch Logos and Images Based on a Control Box Selection