[英]DT::datatables() generated html table shows display anomalies (missing characters) when column level search is used
I am trying to put interactive, sortable tables in html summaries produced by using rmarkdown::render from an R script. 我试图将交互式,可排序的表格放在通过R脚本使用rmarkdown :: render生成的html摘要中。 For producing tables I am using datatables() from DT package.
为了产生表,我使用了DT包中的datatables()。 Reports are generated fine and tables look pretty good, until you do a column level filter/search, after which display shows some funny problems.
报表生成良好,表格看起来也不错,直到您执行列级过滤器/搜索为止,然后显示会出现一些有趣的问题。 My question will become clearer with the following example.
通过以下示例,我的问题将变得更加清楚。
#' ---
#' title: "Test"
#' author: test
#' output:
#' html_document:
#' toc: true
#' ---
#' <style type="text/css">
#' .main-container {
#' max-width: 1200px;
#' margin-left: auto;
#' margin-right: auto;
#' }
#' </style>
#' ### Test data
#+ setup, include=FALSE, echo=TRUE
require(dplyr)
require(DT)
knitr::opts_chunk$set(echo = TRUE)
#+ core_code, include=FALSE, echo=TRUE
plants <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/cluster/plantTraits.csv")
plants<- plants %>%
mutate( ID = paste0("ID_" , sprintf("%04d", 1:136) ) ) %>%
select(ID, X:unsp)
#+ test_table, echo = FALSE
datatable( plants ,
extensions = c("Buttons" , "FixedColumns"),
filter = 'top',
options = list( autoWidth = TRUE ,
dom = 'Blftip',
pageLength = 100,
searchHighlight = TRUE,
buttons = c('copy', 'csv', 'print'),
scrollX = TRUE,
fixedColumns = list(leftColumns = 2)),
class = c('compact cell-border stripe hover') ,
rownames = FALSE)
Produces the table (screenshot): 生成表(屏幕截图):
If I do a search for 048 in the ID column, it shows the right row, like this... 如果我在ID列中搜索048,它会显示右行,如下所示...
But then, if I cancel the filter, and bring all the rows back, rows have characters missing from ID column. 但是,如果我取消过滤器,然后将所有行带回,则ID列中的行缺少字符。
This would happen to any column that I search, or any other data. 我搜索的任何列或任何其他数据都会发生这种情况。 It does not happen if I use the main search box (at right side top corner).
如果使用主搜索框(位于右上角),则不会发生这种情况。 I am running RStudio(Version 1.1.463) on Mac(OS X 10.11.6) but I have tested the produced html file on Chrome, Safari, and RStudio inbuilt browser on Mac;
我在Mac(OS X 10.11.6)上运行RStudio(版本1.1.463),但已在Mac上的Chrome,Safari和RStudio内置浏览器中测试了生成的html文件; and Chrome and IE on Win7.
以及Win7上的Chrome和IE。 Any clues about how to address this?
关于如何解决这个问题的任何线索?
This is not really a solution, but more of circumventing the problem. 这并不是真正的解决方案,而是更多的规避问题。 Since there were no suggestions, I starting disabling all the options I was using and it turns out that it was the highlight search results that was causing the issue.
由于没有任何建议,因此我开始禁用所有正在使用的选项,事实证明,正是突出显示的搜索结果导致了问题。 So if I do:
因此,如果我这样做:
#+ test_table, echo = FALSE
datatable( plants ,
extensions = c("Buttons" , "FixedColumns"),
filter = 'top',
options = list( autoWidth = TRUE ,
dom = 'Blftip',
pageLength = 100,
searchHighlight = FALSE,
buttons = c('copy', 'csv', 'print'),
scrollX = TRUE,
fixedColumns = list(leftColumns = 2)),
class = c('compact cell-border stripe hover') ,
rownames = FALSE)
It works fine now. 现在工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.