R DT datatables with boolean glyphicon
library(shiny) # used for bootstrap
library(DT)
library(htmltools)
# just used to make fake data
library(dplyr)
iris1 <- iris %>%
mutate(
longer = Petal.Length > median(Petal.Length),
wider = Petal.Width > median(Petal.Width)
)
browsable(
fluidPage(
datatable(
iris1,
filter="top",
style="bootstrap",
options = list(
# use rowCallback to change the contents of the table cell
# if data is logical/boolean
rowCallback = htmlwidgets::JS(
"
function(row, data, rowi) {
data.forEach(function(d,i) {
if(typeof(d) === 'boolean') {
$($('td', row)[i]).html(
[
'<span class=\\'',
d ? 'glyphicon glyphicon-ok' : 'glyphicon glyphicon-remove',
'\\'>',
'</span'
].join('')
)
}
})
}
"
)
)
)
)
)