Icons in a datatable (DT)

1,084 views
Skip to first unread message

Alexander Vorobiev

unread,
Mar 23, 2015, 5:29:59 PM3/23/15
to shiny-...@googlegroups.com
Hi,

Is it possible to show icons in the cells? I am using DT and shiny 0.11.1. I tried putting as.character(icon('circle')) into the input data frame then adding the column to 'escape' option in datatable(). When I launch the app the column is empty. Is there anything I can do to make the icons visible?

Thanks,
Alex

Yihui Xie

unread,
Mar 23, 2015, 6:55:58 PM3/23/15
to Alexander Vorobiev, shiny-discuss
shiny::icon() uses the font-awesome library by default, and shiny does
not really know the dependency on font-awesome unless at least one
icon has been rendered in the shiny UI. In your case, you used
as.character(icon()), so shiny has no idea the app depends on
font-awesome (the dependency info is lost through as.character()). Two
possible solutions:

1. Render a hidden icon somewhere in your app, e.g.

fluidPage(
...,
tags$span(icon(), style = "display: none;")
...
)

This will make shiny aware of the font-awesome dependency.

2. Use the glyphicon library instead, since it is shipped with
Bootstrap. You do not need to indicate a special dependency. See ?icon

Regards,
Yihui

Alexander Vorobiev

unread,
Mar 24, 2015, 12:10:49 AM3/24/15
to shiny-...@googlegroups.com, alexander...@gmail.com
Thanks for the advice! I have a follow-up question: do I really have to use as.character(icon(...)) if all I need is insert glyph(s) from font-awesome or glyphicon into my datatable? Is it possible to use <font...> or some class attribute in cells?

Alex

Yihui Xie

unread,
Mar 24, 2015, 9:58:08 PM3/24/15
to Alexander Vorobiev, shiny-discuss
You can _probably_ achieve that by using some special CSS classes on
<td>, but I think it is much more straightforward if you just use
these as.character(icon()) strings in the cells.

Regards,
Yihui


On Mon, Mar 23, 2015 at 11:10 PM, Alexander Vorobiev
Reply all
Reply to author
Forward
0 new messages