Use Font Awesome with gt for tabular data

Use Font Awesome with gt for tabular data

Some websites use a variety of fonts to enhance visualization. Most fonts work for ASCII code characters, some can extend to other panels of unicode, such as recent popular emojis. Some popular font providers include Glyphicons, Font Awesome, Google etc.

Once upon a time Glyphicons was popular as it was combined into a popular Bootstrap CSS. Since now Glyphicons is not free anymore, we need to seek for alternative font.

In a typical HTML webpage structure as <html><head></head><body></body></html>, we can use Font Awesome by put the following statement in the <head> section:

<link rel="stylesheet" >

Then you can use Font Awesome icons in the <body> section, for example arrow-up and arrow-down can be placed around positive or negative numbers, respectively:

<i class="fa fa-arrow-up"></i> +8%

<i class="fa fa-arrow-down"></i> -5%

The full list of icon in Font Awesome is can be found here. (https://www.dhirubhai.net/posts/yinghui-liu-72aa3419_icon-list-in-font-awesome-activity-6694480038785642496-9yfP)

Now we can define a function fontAwesome to do conditional formatting. In this case, we put different icons for positive and negative numbers.

No alt text provided for this image

The code use R htmltools and htmlTable packages to generate HTML based table, and results is:

No alt text provided for this image

To use other R table generation package such as gt, here is the demostration code to show how to use Font Awesome with R gt package:

No alt text provided for this image

Package gt can provide flexible capabilities of column spanner and row grouping. And the result is:

No alt text provided for this image


要查看或添加评论,请登录

Yinghui Liu的更多文章

社区洞察

其他会员也浏览了