i am facing a problem with the new possibility of taking a screenshot of html widgets for further implementation, in for example pdf document. The screenshot of the datatable (DT package) has too high height, which appears as a white space in rmarkdown document (it is easily spotted by the position of the fig.cap, that is way below the end of the datatable).i cannot understand why is this happening and i would like to remove it (no white space under the datatable). Have a look at the example below for the test.Rmd which fully shows the problem:
---
output:
pdf_document:
toc: yes
header-includes:
- \usepackage{fancyhdr}
- \usepackage[ngerman]{babel}
---
\addtolength{\headheight}{1.0cm}
\pagestyle{fancyplain}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\chead{Test}
\lhead{\scriptsize\today}
```{r, fig.align='center', fig.pos='htb!', fig.width=12, fig.cap="The height of screenshot is too high!!",fig.height=3,echo=FALSE, cache=FALSE, warning = FALSE, message = FALSE, tidy=TRUE}
library(DT)
library(webshot)
datatable(mtcars[1:2,],rownames=FALSE, options = list(dom='t',ordering=F))
```

datatable, and i have noticed if the datatable has > 20 rows then figure is well displayed with the caption.rmarkdown is a downloable report that belongs to shiny app), thats why in example i have used only two rows from mtcars dataset. Can you try to add the following to r chunk and see if this works:
screenshot.opts = list(delay = 1, cliprect = c(0, 0, 1000, 150)), dev='jpeg'

I had this issue in a Shiny app using renderUI to render a datatable object. I had to add width = 100% and height = 100%. So maybe try:
datatable(mtcars[1:2, ], rownames = FALSE, options = list(dom = "t", ordering = F), height = "100%")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With