在RmarkDown中的DataTable HTML小部件下删除额外的空间

发布于 2025-02-10 14:33:51 字数 1081 浏览 0 评论 0 原文

我正在使用rmarkDown创建HTML报告,该报告具有 dt :: dataTable()函数生成的一些交互式表看一点,到目前为止,我一直无法摆脱它。

这就是数据的间距通常在数据表和下一个图之间的样子:

“在此处输入图像说明”

这是额外空间的间距:

”

似乎只发生了桌子上有少量的行(< 5),这使我怀疑它的空间至少为10行。基于此,我尝试设置DataTable选项 pageLength = 5 lentheMenu = c(5、10、15、20) ,也尝试了 fillContainer = false ,但到目前为止尚无奏效。

下面显示了直接生成表和图的代码,并从单独的函数中调用,因为除了每次不同输入的其他图外,我还创建了大量表。该图是GGPLOT对象。

model_obj$data  %>%
  DT::datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                               buttons = c('excel'))) %>%
  knitr::knit_print() %>%
  cat()
  
cat("\n\n#### Title \n\n")
print(model_obj$plot1)

I'm creating an html report with rmarkdown that has some interactive tables generated by the DT::datatable() function and for some of them there is extra whitespace under the table which makes the formatting of the report look a little off and so far I have been unable to get rid of it.

This is what the spacing looks like normally between the datatable and the next plot:

enter image description here

This is what the spacing looks like with the extra space:

enter image description here

It seems to only be happening with tables that have a small number of rows (<5) which made me suspect its holding the space for a table with a minimum of 10 rows. Based on this, I tried setting the datatable options pageLength = 5 and lengthMenu = c(5, 10, 15, 20) and also tried fillContainer = FALSE but nothing so far has worked.

The code to generate the tables and plots directly under is shown below and is called from a separate function because I'm creating a large number of tables in addition to other plots with different inputs each time. The plot is a ggplot object.

model_obj$data  %>%
  DT::datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                               buttons = c('excel'))) %>%
  knitr::knit_print() %>%
  cat()
  
cat("\n\n#### Title \n\n")
print(model_obj$plot1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文