Is it possible to have sortable (Interactive) table in rMarkdown?

Avinash picture Avinash · Nov 25, 2014 · Viewed 14.2k times · Source

I am using kable() from knitr package to show a table on a html document. Is it possible to make it sortable? Some sample code,

---
title: "Test"
output: html_document
---

```{r, echo=FALSE, comment=""}
kable(data.frame("a"=1:10,"b"=11:20),digits=2)
```

Answer

Yihui Xie picture Yihui Xie · Jan 8, 2015

The package DT (https://github.com/rstudio/DT) is an R interface to the JavaScript library DataTables. You can use it in R Markdown, e.g.

```{r}
DT::datatable(iris)
```