I want to get my data.frame from shown as a html table, using java script dataTables for a nicer look. I want to use knitr for translating the data.frame from R into html. I know, there is the function kable to construct such a table. But there i dont know, maybe it is not possible, how to define, that some cell has, e.g., the background coloured red, another one yellow. Can this be done. The problem is, for using the javascript dataTables, I need an id for the html table I created with knitr...
1 Answer
It is possible to add a id to a html table with kable through the table.attr param.
kable(head(cars), format = 'html', table.attr = 'id="foo"')
and then in JavaScript
$(document).ready(function() {
$('#foo').dataTable();
} );
To directly create a dataTable from a data.frame use dTable from the rCharts package.
dTable(cars)
1 Comment
stephan mc
Og course. Unfortunately my question was not how to assign the id, i wanted to know, if there is a possibility to say, that a special cell should be in red or so. If I can use dtable therefore, ok. But I liked the shaped of the tables js datatables. Thank nevertheless thanks for your answer