Display Tables with the JavaScript Library DataTables

jQuery DataTables

We can use the JavaScript library DataTables to generate enhanced tables in HTML. In the example below, we create a table for the mtcars data:

kable(mtcars, 'html', table.attr='id="mtcars_table"')

Note we assigned an id to the table, and next we use the DataTables library to initialize the table and you will get an interactive table.

window.addEventListener('load', () => {

By comparison, below is an ordinary table:

kable(head(mtcars), 'html')

This vignette is only a toy example. I'd recommend you to use the DT package instead: https://github.com/rstudio/DT

Try the knitr package in your browser

Any scripts or data that you put into this service are public.

knitr documentation built on June 22, 2024, 9:25 a.m.