2
votes

The DT (datatables) library for R provides the minimal example for working with shiny below at http://rstudio.github.io/DT/extensions.html (this works for me)

library(shiny)
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris, options = list(lengthChange = FALSE)
    )
  }
)

However, the following code in a shiny RMarkdown document doesn't display any output. Why is that?

```{r}
library(rmarkdown); library(knitr); library(DT)

mydt = DT::renderDataTable(iris)
DT::dataTableOutput('mydt')
```

renderPrint(DT::dataTableOutput('mydt')) also doesn't display the table, though it displays some html info about the table.

I don't understand why defining the datatable with DT::renderDataTable() and displaying it with DT::dataTableOutput() works in a shiny app but not a shiny document. Though I presume I'm misunderstanding something.

1
hello, may I ask if you managed to have the datatable object displayed in a pdf document at the end?hartmut

1 Answers

2
votes

All you need is DT::renderDataTable(iris).

```{r}
DT::renderDataTable(iris)
```

I don't understand what you mean by 1) assigning DT::renderDataTable(iris) to an R object mydt, 2) printing DT::dataTableOutput('mydt'), and 3) renderPrint(DT::dataTableOutput('mydt')). None of these make sense in this document.