Home > Back-end >  Is there a way to rename column names with icons
Is there a way to rename column names with icons

Time:02-23

Is there a way to add an icon to column headers by renaming it . I tried with below

datatable((iris %>% rename(paste0('Sepal.Width',as.character(icon(name = "info-circle", lib = "font-awesome"))) = Sepal.Width)))

So I need a small icon next to Sepal.Width, so tried like above. But I am not getting any result. Can anyone help me?

CodePudding user response:

You can use the gt package, which accepts html code as column names and the enter image description here

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.

  •  Tags:  
  • r dt
  • Related