rr-markdownknitrdt

DT table will not show in Rmarkdown with Word output


I am trying to render a static DT to word.

I have this stripped down version of a file example.Rmd and I am using knitr version 1.30 and the latest stable versions of all relevant packages. Per https://bookdown.org/yihui/bookdown/html-widgets.html the datatable should render but I am not getting the static DT back just the echo=TRUE part.

Please help me if you can - I am hopelessly stuck and I cannot just use another table.


title: 'Main title'
subtitle: 'Subtitle here'
always_allow_html: yes
# params:these will come from SHINY APP
#   x1: x1
#   x2: x2
#   x3 :x3
output:
   word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(out.width = '100%', dpi=300)

```

```{r, fig.align='center', echo=TRUE, cache=FALSE, warning = TRUE, message = TRUE, tidy=TRUE}
library(DT)
library(webshot)
if(is.null(webshot:::find_phantom())){webshot::install_phantomjs()}

DT::renderDataTable(iris)
```

Solution

  • The solution to this problem is to replace renderDataTable with datatable which allows webshot to kick in.

    title: 'Main title'
    subtitle: 'Subtitle here'
    always_allow_html: yes
    # params:these will come from SHINY APP
    #   x1: x1
    #   x2: x2
    #   x3 :x3
    output:
       word_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    knitr::opts_chunk$set(out.width = '100%', dpi=300)
    
    ```
    
    ```{r, fig.align='center', echo=TRUE, cache=FALSE, warning = TRUE, message = TRUE, tidy=TRUE}
    library(DT)
    library(webshot)
    if(is.null(webshot:::find_phantom())){webshot::install_phantomjs()}
    
     DT::datatable(iris)
    ```