Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering not working with renderDT in flexdashboard #150

Open
nikitautiu opened this issue Jul 3, 2024 · 0 comments
Open

Filtering not working with renderDT in flexdashboard #150

nikitautiu opened this issue Jul 3, 2024 · 0 comments

Comments

@nikitautiu
Copy link

nikitautiu commented Jul 3, 2024

🐛 Bug

Description

Even when using client-side processing by passing server = FALSE to renderDT, filtering does not work properly in flexdashboard. Filtering does work properly when not using reactive rendering or when using reactive rendering with renderDT in a script-based shiny app.

How to reproduce

---
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    theme: 
      version: 5
  
runtime: shiny
---

```{r setup, include=FALSE, echo = FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# CAR VIEW 


## Sidebar {.sidebar}
### 

```{r, echo = FALSE}
shared_car_data <- crosstalk::SharedData$new(mtcars)
crosstalk::filter_checkbox("car_carb", "carb", shared_car_data, ~ carb)
```

##
###
```{r, echo =FALSE}
# DOESN'T WORK!

DT::renderDT(
  DT::datatable(shared_car_data), server = FALSE
)
```

##
###
```{r, echo = FALSE}
# WORKS

DT::datatable(shared_car_data)
```

The second block yields correct results when filtering, whereas the renderDT one does not.

image

A minimal shiny app using renderDT which yields the proper results:

shared_car_data <- crosstalk::SharedData$new(mtcars)

ui <- shiny::fluidPage(
  shiny::titlePanel("CAR VIEW"),
  shiny::sidebarLayout(
    shiny::sidebarPanel(
      crosstalk::filter_checkbox("car_carb", "carb", shared_car_data, ~carb)
    ),
    shiny::mainPanel(
      DT::dataTableOutput("car_table")
    )
  )
)

server <- function(input, output, session) {
  output$car_table <- DT::renderDT({
    DT::datatable(shared_car_data)
  }, server = FALSE)
}

# Run the app
shinyApp(ui = ui, server = server)

Filtering for carb == 8 yields the same results as the second cell in the flexdashbaord:

image

Intended behaviour

I assume all 3 examples should yield the same results post filtering.

sessionInfo()

R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] crosstalk_1.2.1     DT_0.33             flexdashboard_0.6.2
[4] shiny_1.8.1.1      

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.8    compiler_4.3.2    promises_1.2.1    Rcpp_1.0.12      
 [5] stringr_1.5.1     later_1.3.2       jquerylib_0.1.4   yaml_2.3.8       
 [9] fastmap_1.1.1     mime_0.12         R6_2.5.1          knitr_1.45       
[13] htmlwidgets_1.6.4 tibble_3.2.1      bslib_0.6.1       pillar_1.9.0     
[17] rlang_1.1.3       utf8_1.2.4        cachem_1.0.8      stringi_1.8.3    
[21] httpuv_1.6.14     xfun_0.41         fs_1.6.3          sass_0.4.8       
[25] lazyeval_0.2.2    memoise_2.0.1     cli_3.6.2         magrittr_2.0.3   
[29] digest_0.6.34     rstudioapi_0.15.0 xtable_1.8-4      lifecycle_1.0.4  
[33] vctrs_0.6.5       evaluate_0.23     glue_1.7.0        fansi_1.0.6      
[37] rmarkdown_2.25    tools_4.3.2       pkgconfig_2.0.3   ellipsis_0.3.2   
[41] htmltools_0.5.7  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant