Debian Codegraph @

inst/doc/datatables.Rmd

raw
1 ---
2 title: Display Tables with the JavaScript Library simple-datatables
3 author: Yihui Xie
4 date: "`{r} Sys.Date()`"
5 output:
6 html:
7 meta:
8 css: ["@default", "@npm/simple-datatables/dist/style.min.css"]
9 js: ["@npm/simple-datatables/dist/umd/simple-datatables.min.js"]
10 ---
11
12 <!--
13 %\VignetteEngine{litedown::vignette}
14 %\VignetteIndexEntry{Display Tables with the JavaScript Library simple-datatables}
15 -->
16
17 We can use the JavaScript library [**simple-datatables**](https://github.com/fiduswriter/simple-datatables/) to generate enhanced tables in HTML. In the example below, we create a table for the `mtcars` data:
18
19 ::: {#mtcars-table}
20 ```{r cool, print.args=list(data.frame=list(limit=NULL))}
21 mtcars
22 ```
23 :::
24
25 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.
26
27 ```{js}
28 window.addEventListener('load', () => {
29 new simpleDatatables.DataTable('#mtcars-table > table');
30 });
31 ```
32
33 By comparison, below is an ordinary table:
34
35 ```{r boring}
36 mtcars
37 ```