gpt4 book ai didi

Rmarkdown 重叠输出

转载 作者:行者123 更新时间:2023-12-04 18:27:14 25 4
gpt4 key购买 nike

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

enter image description here

下面的可重现示例(改变 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 Test

```{r echo=FALSE}
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)
```

最佳答案

查看您的示例生成的 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>

或者,如果你更喜欢用 CSS 保持你的 RMarkdown 整洁,把
div.datatables {
height: auto !important;
}

在一个单独的 CSS 文件中,并在 RMarkdown header 中链接到它,如下所示:
---
title: "Test links to sections in DT"
output:
html_document:
css: overlap_workaround.css
---

关于Rmarkdown 重叠输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42361888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com