You can use the gt
package, which accepts html code as column names and the icons
package which delivers the proper html code:
library(tidyverse)
library(gt)
iris %>%
head() %>%
gt() %>%
cols_label(
Sepal.Width = html(as.character(icons::fontawesome("info-circle")))
)
Created on 2022-02-23 by the reprex package (v2.0.1)
This displays the icon as a column name, but the column name in the data.frame is not changed. I assumed this is what you actually want, given the use of DT::datatable
in your example.
Otherwise, you could use:
colnames(iris) <- c("Sepal.Length",
as.character(icons::fontawesome("info-circle")),
"Petal.Length",
"Petal.Width",
"Species")
But it would be much more complicated to display the actual icon and not the underlying html code.
?make.names
. – Jovia