Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White space from datatable screenshot in Rmarkdown PDF

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))
```

enter image description here

  • Additionally i have tried different number of displayed rows in datatable, and i have noticed if the datatable has > 20 rows then figure is well displayed with the caption.
  • However my table in original pdf file has for example 2 rows (can be bit more --> the number of rows is reactive, as this rmarkdown is a downloable report that belongs to shiny app), thats why in example i have used only two rows from mtcars dataset.
like image 857
Mal_a Avatar asked Jun 22 '17 10:06

Mal_a


2 Answers

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'

enter image description here

like image 90
AK88 Avatar answered Oct 31 '22 21:10

AK88


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%")
like image 26
Mark White Avatar answered Oct 31 '22 19:10

Mark White