Search code examples
rflextable

Add fontawesome icons to flextable


I want to add some decorative icons to my flextable tables. I already managed to add some fotawesome icons to my table using the hyperlink_text() function:

library(flextable)
library(fontawesome)
library(dplyr)

# smaple data
pets = tribble(~Name, ~Type, ~Age,
               'Barley', 'dog', 8,
               'Honey', 'dog', 1,
               'Tiger', 'cat', 2,
               'Jack', 'cat', 9)

# add icons to table
pets %>% 
  rowwise() %>% 
  mutate(Type = paste0('<a href="">', as.character(fa(Type)), "</a>")) %>% 
  flextable() %>% 
  compose(j = "Type",
          value = as_paragraph(hyperlink_text(x = '', url = Type) ) )

However, I would prefer to display only the icons without any link attached to it. How can I do that?


Solution

  • I had some success with this by following the steps outlined in the flextable book, section 8.5. First, you should save the icons you want to use locally and add the file paths of those icons to your data frame. See an example of how this would look in section 15.1 in the flextable book.

    Then, you can tell flextable to display the icons with the colformat_image() function.