rstudio / DT

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

scroll bars do not appear when renderDataTable is used in flexdashboard #818

Open nitingupta2 opened 4 years ago

nitingupta2 commented 4 years ago

Quite possibly a bug - not sure whether in DT or flexdashboard.

Here's the problem: I'm rendering a datatable in a shiny flexdashboard app in a reactive context, so that it updates when an input in changed. My dataset isn't large enough to use pagination, so the user should be able to scroll in Y direction to see all records. However, scroll bars do not appear when the table is updated in renderDataTable.

This issue has been asked on StackOverflow here without a satisfactory resolution.

Here's how the problem can be reproduced within a simple shiny flexdashboard Rmd file. In comparison, the scroll bars appear in renderTable as expected. Similarly, datatable also works as expected when used in a non-reactive context with a fixed input.

To be sure, I have tried both the current CRAN and development versions of DT and flexdashboard without success.

---
title: "Test Flexboard Shiny App"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(shinythemes)
library(DT)
library(tidyverse)

Sidebar {.sidebar}

selectInput("data_set", "Pick a dataset", choices = c("mtcars","airquality"), selected = "mtcars")

# Input dataset
mydataset <- reactive({

  name <- input$data_set
  df <- switch(name,
               "mtcars" = mtcars,
               "airquality" = airquality)

  return(df)
})

Column {data-width=500}

renderTable (reactive)


renderTable(mydataset(), rownames = TRUE)

Column {data-width=500}

renderDataTable (reactive)


DT::renderDataTable(datatable(mydataset(), rownames = TRUE,
                              options = list(bPaginate = FALSE, searching = FALSE, info = FALSE)))

datatable (fixed input)


datatable(mtcars, rownames = TRUE, 
          options = list(bPaginate = FALSE, searching = FALSE, info = FALSE))

``` r
xfun::session_info()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18362)
#> 
#> Locale:
#>   LC_COLLATE=English_United States.1252 
#>   LC_CTYPE=English_United States.1252   
#>   LC_MONETARY=English_United States.1252
#>   LC_NUMERIC=C                          
#>   LC_TIME=English_United States.1252    
#> 
#> Package version:
#>   askpass_1.1              assertthat_0.2.1         backports_1.1.7         
#>   base64enc_0.1.3          BH_1.72.0.3              blob_1.2.1              
#>   broom_0.5.6              callr_3.4.3              cellranger_1.1.0        
#>   cli_2.0.2                clipr_0.7.0              colorspace_1.4-1        
#>   compiler_3.6.3           crayon_1.3.4             crosstalk_1.1.0.1       
#>   curl_4.3                 DBI_1.1.0                dbplyr_1.4.4            
#>   desc_1.2.0               digest_0.6.25            dplyr_1.0.0             
#>   DT_0.13.4                ellipsis_0.3.1           evaluate_0.14           
#>   fansi_0.4.1              farver_2.0.3             fastmap_1.0.1           
#>   flexdashboard_0.5.1.9000 forcats_0.5.0            fs_1.4.1                
#>   generics_0.0.2           ggplot2_3.3.1            glue_1.4.1              
#>   graphics_3.6.3           grDevices_3.6.3          grid_3.6.3              
#>   gtable_0.3.0             haven_2.3.1              highr_0.8               
#>   hms_0.5.3                htmltools_0.4.0          htmlwidgets_1.5.1.9001  
#>   httpuv_1.5.4             httr_1.4.1               isoband_0.2.1           
#>   jsonlite_1.6.1           knitr_1.28               labeling_0.3            
#>   later_1.1.0.1            lattice_0.20-41          lazyeval_0.2.2          
#>   lifecycle_0.2.0          lubridate_1.7.9          magrittr_1.5            
#>   markdown_1.1             MASS_7.3.51.6            Matrix_1.2.18           
#>   methods_3.6.3            mgcv_1.8.31              mime_0.9                
#>   modelr_0.1.8             munsell_0.5.0            nlme_3.1-148            
#>   openssl_1.4.1            pillar_1.4.4             pkgbuild_1.0.8          
#>   pkgconfig_2.0.3          pkgload_1.1.0            plyr_1.8.6              
#>   praise_1.0.0             prettyunits_1.1.1        processx_3.4.2          
#>   progress_1.2.2           promises_1.1.0           ps_1.3.3                
#>   purrr_0.3.4              R6_2.4.1                 RColorBrewer_1.1.2      
#>   Rcpp_1.0.4.6             readr_1.3.1              readxl_1.3.1            
#>   rematch_1.0.1            reprex_0.3.0             reshape2_1.4.4          
#>   rlang_0.4.6              rmarkdown_2.2            rprojroot_1.3.2         
#>   rstudioapi_0.11          rvest_0.3.5              scales_1.1.1            
#>   selectr_0.4.2            shiny_1.4.0.2            shinythemes_1.1.2       
#>   sourcetools_0.1.7        splines_3.6.3            stats_3.6.3             
#>   stringi_1.4.6            stringr_1.4.0            sys_3.3                 
#>   testthat_2.3.2           tibble_3.0.1             tidyr_1.1.0             
#>   tidyselect_1.1.0         tidyverse_1.3.0          tinytex_0.23            
#>   tools_3.6.3              utf8_1.1.4               utils_3.6.3             
#>   vctrs_0.3.1              viridisLite_0.3.0        whisker_0.4             
#>   withr_2.2.0              xfun_0.14                xml2_1.3.2              
#>   xtable_1.8-4             yaml_2.2.1

Created on 2020-06-08 by the reprex package (v0.3.0)


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.

AnachronicNomad commented 4 years ago

I can confirm that this is an ongoing issue; including after the most recent release 17 days ago.

> xfun::session_info('DT')
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS, RStudio 1.3.959

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3   BH_1.72.0.3       crosstalk_1.1.0.1 digest_0.6.25     DT_0.15.4         graphics_4.0.2   
  grDevices_4.0.2   htmltools_0.5.0   htmlwidgets_1.5.1 jsonlite_1.7.0    later_1.1.0.1     lazyeval_0.2.2   
  magrittr_1.5      methods_4.0.2     promises_1.1.1    R6_2.4.1          Rcpp_1.0.5        rlang_0.4.7      
  stats_4.0.2       utils_4.0.2       yaml_2.2.1       
> 
nitingupta2 commented 3 years ago

Would appreciate if a package maintainer could comment whether this issue is under review.

Thank you.

shrektan commented 3 years ago

Thanks for reporting this issue. I can confirm it. I'm investigating this now...

shrektan commented 3 years ago

OK, adding fillContainer = TRUE to datatable() will resolve this. (Ref to #243)

Here're some facts:

So we'd better enable fillContainer for renderDT() in Flexdashboard automatically.


@nitingupta2 As of your problem, I mean changing the chunk as below will be enough :

### renderDataTable (reactive)

```{r}

DT::renderDataTable(datatable(mydataset(), rownames = TRUE,
                              options = list(bPaginate = FALSE, searching = FALSE, info = FALSE),
                              fillContainer = TRUE))
shrektan commented 3 years ago

Well, now it looks like an issue of FlexDashboard to me, as the fillContainer option should be enable there:

https://github.com/rstudio/flexdashboard/blob/6ad5aceb16b07850535786c45a0e55f114f4d2d7/R/flex_dashboard.R#L189-L194

However, under Shiny mode, these lines will fail to work, apparently.

So I will file an issue on FlexDashboard.