flexdashboard icon indicating copy to clipboard operation
flexdashboard copied to clipboard

DT::renderDataTable Example Broken

Open t-kalinowski opened this issue 8 years ago • 1 comments

Hello,

I had some code working on macOS which then broke when I switched to windows. I isolated it to DT::renderDataTable.

The exact example on the documentation website that's broken is here: (http://rmarkdown.rstudio.com/flexdashboard/using.html), specifically this snippet:

### Cars

```{r}
DT::renderDataTable({
  data <- head(mtcars, n = input$maxrows)
  DT::datatable(data, options = list(
    bPaginate = FALSE
  ))
})

Here is a reproducible minimal example showing DT::renderDataTable not working where shiny::renderDataTable and shiny::renderTable both still work.

---
title: "Bug Report"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
data(mtcars)
```

Column {.sidebar}
---------------------------------------------------------------------
```{r}
shiny::sliderInput("maxrows", "max rows", 1, 40, 10, 1)
```


Column 
-----------------------------------------------------------------------
```{r}
mtcars2 <- reactive({head(mtcars, n = input$maxrows)})
```

```{r}
DT::renderDataTable({
  DT::datatable(mtcars2(), options = list(
    bPaginate = FALSE
  ))
})
```

Column 
-----------------------------------------------------------------------

```{r}
shiny::renderDataTable({mtcars2()})
```

```{r}
shiny::renderTable({mtcars2()})
```

After running this document, the reactive elements are not drawn. image

However, if I create at DT::datatable outside a reactive context first, then all the datatable created in the reactive context draws. So adding in this chunk

### Not-reactive DT::Datatable
```{r}
DT::datatable(mtcars, options = list(
  pageLength = 25
))
```

yeilds this

image

t-kalinowski avatar Dec 20 '16 15:12 t-kalinowski

In case anyone else runs into this before it is fixed: A quick workaround is to add this chunk to the document right after the global chunk.

```{r, include = FALSE}
DT::datatable(data.frame(x=1))
```

t-kalinowski avatar Dec 20 '16 15:12 t-kalinowski