我报告了一个问题,https://github.com/rstudio/rmarkdown/issues/967,我想知道是否有一个解决办法(如何使这个工作)这一点?

下面是可重复的示例(请更改n和nGroup以查看效果-当n= 100和nGroup=10时不重叠):
---
title: "Test links to sections in DT"
output: html_document
---
```{r setup, include=FALSE}knitr::opts_chunk$set(echo=FALSE)
knitr::opts_chunk$set(message=FALSE)
knitr::opts_chunk$set(warning=FALSE)
DT测试
library(DT)
n <- 1000
nGroup <- 100
testDF <- data.frame(text=paste0("Section", 1:n),
number=1:n,
group=rep(1:(n/nGroup), n/nGroup))
datatable(head(testDF), caption="Whole table", rownames=FALSE, escape=FALSE, options=list(paging=FALSE, info=FALSE))
getDT<-function(x) {
a <- list()
a[[1]] <- htmltools::tags$h3("test1")
a[[2]] <- datatable(x[, c("text", "number")], caption=htmltools::tags$caption(style="caption-side: top; text-align: left;", "Group: ", htmltools::strong(x$group)), rownames=FALSE, escape=FALSE, filter=c("none"), options=list(paging=FALSE, info=FALSE))
a[[3]] <- htmltools::tags$h4("test1")
return(a)
}
res <- lapply(split(testDF, testDF$group), getDT)
htmltools::tagList(res)发布于 2017-02-23 09:00:33
看看您的示例生成的HTML,我看到了一堆div标记,它们如下所示:
<div class="datatables html-widget html-widget-static-bound"
id="htmlwidget-3efe8ca4aa087193f03e"
style="width:960px;height:500px;">注意内联样式,它将高度设置为500像素。然而,div内部的内容要比500个像素高得多,因此它已经超过了div的边界。
我不知道500px是从哪里来的,但作为一种解决办法,您可以用不同的样式覆盖它。例如,将其添加到您的RMarkdown顶部(在标题之后):
<style type="text/css">
div.datatables { height: auto !important;}
</style>或者,如果您希望您的RMarkdown与CSS保持整洁,请将
div.datatables {
height: auto !important;
}在一个单独的CSS文件中,并在RMarkdown头中链接到它,如下所示:
---
title: "Test links to sections in DT"
output:
html_document:
css: overlap_workaround.css
---https://stackoverflow.com/questions/42361888
复制相似问题