rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
597 stars 182 forks source link

Cannot use container in Shiny #997

Closed stla closed 2 years ago

stla commented 2 years ago

Hello,

When using a container outside Shiny that works fine:

sketch <- htmltools::withTags(table(
  class = "display",
  thead(
    tr(
      th(rowspan = 2, "Species"),
      th(colspan = 2, "Sepal"),
      th(colspan = 2, "Petal")
    ),
    tr(
      lapply(rep(c("Length", "Width"), 2), th)
    )
  )
))

datatable(
  head(iris, 10),
  container = sketch
)

DTnonempty

But when I do the same in a Shiny app, the table is empty:

ui <- fluidPage(

  DTOutput("DTtable"),

  actionButton("export", "Export table")
)

server <- function(input, output, session){

  sketch = htmltools::withTags(table(
    class = "display",
    thead(
      tr(
        th(rowspan = 2, "Species"),
        th(colspan = 2, "Sepal"),
        th(colspan = 2, "Petal")
      ),
      tr(
        lapply(rep(c("Length", "Width"), 2), th)
      )
    )
  ))

  output$DTtable <- renderDT({
    datatable(
      head(iris, 10),
      container = sketch
    ) 
  })

}

shinyApp(ui, server)

DTempty

What's wrong here?

> xfun::session_info()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042), RStudio 2021.9.0.351

Locale:
  LC_COLLATE=French_Belgium.1252  LC_CTYPE=French_Belgium.1252   
  LC_MONETARY=French_Belgium.1252 LC_NUMERIC=C                   
  LC_TIME=French_Belgium.1252    

Package version:
  base64enc_0.1.3   bslib_0.3.1       cachem_1.0.6      cli_3.2.0        
  commonmark_1.8.0  compiler_4.1.2    crayon_1.5.1      crosstalk_1.2.0  
  digest_0.6.29     DT_0.23           ellipsis_0.3.2    evaluate_0.15    
  fastmap_1.1.0     fontawesome_0.2.2 fs_1.5.2          glue_1.6.2       
  graphics_4.1.2    grDevices_4.1.2   highr_0.9         htmltools_0.5.2  
  htmlwidgets_1.5.4 httpuv_1.6.5      jquerylib_0.1.4   jsonlite_1.8.0   
  knitr_1.39        later_1.3.0       lazyeval_0.2.2    lifecycle_1.0.1  
  magrittr_2.0.2    methods_4.1.2     mime_0.12         promises_1.2.0.1 
  R6_2.5.1          rappdirs_0.3.3    Rcpp_1.0.8.3      rlang_1.0.2      
  rmarkdown_2.13    sass_0.4.0        shiny_1.7.1       shinyjs_2.1.0    
  sourcetools_0.1.7 stats_4.1.2       stringi_1.7.6     stringr_1.4.0    
  tinytex_0.37      tools_4.1.2       utils_4.1.2       withr_2.5.0      
  xfun_0.31         xtable_1.8-4      yaml_2.3.5  

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

stla commented 2 years ago

Ah ok this works if I unset the row names!