【发布时间】:2018-12-17 05:33:21
【问题描述】:
我正在使用 RMarkdown 和 DT 包在 HTML 报告中创建动态表。我正在尝试通过添加 [filter = 'top'] 来添加列过滤器,如 DT 包文档中所述,以便用户可以单独搜索每一列。但是,当我编织到 HTML 时,列级过滤器就在那里,但它们不起作用。我正在使用最新版本的 R Studio 和 DT 包的 0.4 版本。我做错了什么?
---
title: <b>Report</b>
date: Updated `r format(Sys.time(), '%B %d, %Y')`
output:
rmarkdown::html_document:
theme: cosmo
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rmarkdown)
library(DT)
library(htmltools)
library(knitr)
```
###Tab 1: Alphabetic List of Fields
```{r by.field, echo=FALSE,results="asis",warning=FALSE}
#Making the table
fieldname=binned_data$Attribute.from.EHR.database
field_def=binned_data$Definition
field_table=binned_data$Table
fieldtable=data.frame(fieldname, field_def, field_table)
print(htmltools::tagList(
datatable(
fieldtable, colnames=c(
"Field","Definition", "Table"),
filter = 'top',
options = list(autowidth = TRUE,
order = list(list(0, 'asc')),
columnDefs = list(list(className = 'dt-left', targets = c(0,1,2))),
pageLength = 25,
lengthMenu = c(25, 50, 75, 100, 150),
initComplete = JS("
function(settings, json) {
","
$('body').css({
'font-family': 'Century Gothic', 'font-size': '150%'
});
$(this.api().table().header()).css({
'font-family': 'Century Gothic',
'font-size':'125%',
'background-color': '#008000',
'color': '#fff'
});
}
")
),rownames = FALSE
)))
```
这是输出的样子,但是当我开始在列过滤器框中输入时,没有任何反应。 Output
【问题讨论】:
标签: rstudio r-markdown dt