Skip to content

updateSearch() doesn't filter in the same way manual filters do #1082

@DavidBlairs

Description

@DavidBlairs

Hello!

I've encountered a bug in the updateSearch function that is making it rather unusable. The code to reproduce it can be found below:

library(shiny)
library(DT)

ui <- fluidPage(
  actionButton("change_filters", "Change Filters"),
  DTOutput("mytable")
)

server <- function(input, output, session) {
  output$mytable <- renderDT(datatable(iris, filter = "top"))
  
  proxy <- dataTableProxy("mytable")
  
  observe({
    print(input$mytable_search_columns)
  })
  
  observeEvent(input$change_filters, {
    updateSearch(proxy, keywords = list(global = NULL, columns = c("", "", "", "", "", "[\"setosa\"]")))
  })
}

shinyApp(ui, server)

If you open this app and click the button labelled "change_filters", it works as expected and adds the categorical filter to the last column in the the table. However:

  1. The first issue you'll notice is that the button that allows you to remove the filters (a black circle with a black x in the in the middle on the right of the filter box) is not there and you need to click inside of the filter box and out again for it to appear. This is perhaps the lesser of the two issues.
  2. The second issue is that if you remove this filter, the table does not update. As well as this, while applying other filters manually works as expected, you are never able to return to the original completely unfiltered dataset from this point onwards.

I've tried updating the package and using the latest development version but this doesn't seem to work.


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions