ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
783 stars 207 forks source link

Issue with bootstrap theme and DT in htmlwidgets 0.9 #281

Open vnijs opened 7 years ago

vnijs commented 7 years ago

@jcheng5 It seems that commit https://github.com/ramnathv/htmlwidgets/commit/5ff51ff3ae979daa8eca9e21cf82a954cf459ea7 may cause an issue when styling a DT table with a bootstrap theme in a Shiny App (see screenshot below). DT tables in the same app are rendered fine with the prior commit. I don't have a minimal regex yet so I'm posting this issue more as reminder that I need to create one :)

screen shot 2017-06-29 at 6 52 27 pm

vnijs commented 6 years ago

Issue occurs when using renderUI and returning NULL while DT::renderDataTable waits for inputs to become available. Using req instead seems to resolve the issue

jcheng5 commented 6 years ago

Hmm, OK. Can you show the code that styles the table with a bootstrap theme?

vnijs commented 6 years ago

I think the Rmd below illustrates what is going on. In a regular shiny app, imagine you have an output with renderDataTable but the data for the table it should render is not (yet) available. If you then use something like if (is.null(mydata)) return() inside renderDataTable non-bootstrap styling is included although no table is displayed. Then when the data does become available for a DT table with bootstrap styling, both styles are applied. Note that this happens with 0.9 but not in 0.8.

Using req in a shiny app or replacing the NULL line below with DT::datatable(NULL, style = "bootstrap") would have fixed the problem.

---
title: "DT-bootstrap"
output: html_document
runtime: shiny
---

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

```{r}
DT::renderDataTable({
  DT::datatable(mtcars, style = "bootstrap")
})
```