2

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 1

1

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) 
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.