-
-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: knitr | ||
Type: Package | ||
Title: A General-Purpose Package for Dynamic Report Generation in R | ||
Version: 1.48.3 | ||
Version: 1.48.4 | ||
Authors@R: c( | ||
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")), | ||
person("Abhraneel", "Sarma", role = "ctb"), | ||
|
@@ -156,7 +156,7 @@ License: GPL | |
URL: https://yihui.org/knitr/ | ||
BugReports: https://github.com/yihui/knitr/issues | ||
Encoding: UTF-8 | ||
VignetteBuilder: knitr | ||
VignetteBuilder: litedown, knitr | ||
SystemRequirements: Package vignettes based on R Markdown v2 or reStructuredText require Pandoc (http://pandoc.org). | ||
The function rst2pdf() requires rst2pdf (https://github.com/rst2pdf/rst2pdf). | ||
Collate: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
--- | ||
title: Display Tables with the JavaScript Library DataTables | ||
author: Yihui Xie | ||
date: "`r Sys.Date()`" | ||
date: "`{r} Sys.Date()`" | ||
output: | ||
markdown::html_format: | ||
litedown::html_format: | ||
meta: | ||
css: ["@default", "@prism-xcode", "https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css"] | ||
css: ["@default", "https://cdn.datatables.net/1.13.7/css/jquery.dataTables.min.css"] | ||
js: ["@npm/[email protected]/dist/jquery.min.js", "https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"] | ||
--- | ||
|
||
<!-- | ||
%\VignetteEngine{knitr::knitr_notangle} | ||
%\VignetteEngine{litedown::vignette} | ||
%\VignetteIndexEntry{Display Tables with the JavaScript Library DataTables} | ||
--> | ||
|
||
## jQuery DataTables | ||
|
||
We can use the JavaScript library [**DataTables**](https://datatables.net) to generate enhanced tables in HTML. In the example below, we create a table for the `mtcars` data: | ||
|
||
```{r cool, results='asis'} | ||
library(knitr) | ||
kable(mtcars, 'html', table.attr='id="mtcars_table"') | ||
::: {#mtcars-table} | ||
```{r cool, print.args=list(data.frame=list(limit=NULL))} | ||
mtcars | ||
``` | ||
::: | ||
|
||
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. | ||
|
||
```{js} | ||
window.addEventListener('load', () => { | ||
$('#mtcars_table').DataTable(); | ||
$('#mtcars-table > table').DataTable(); | ||
}); | ||
``` | ||
|
||
By comparison, below is an ordinary table: | ||
|
||
```{r boring, results='asis'} | ||
kable(head(mtcars), 'html') | ||
```{r boring} | ||
mtcars | ||
``` | ||
|
||
This vignette is only a toy example. I'd recommend you to use the **DT** package instead: https://github.com/rstudio/DT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters