2
votes

probably easy but somehow cannot get it done, what's the best way to reset filters in shiny DT? I have a very wide table and I do not want someone to do some filtering forgetting they had filtered another column outside of the screen width - I would rather have a button to clear all filters. Is a change of dom/turning filter on/off the only way? Sorry if it is a duplicate - I checked the archive and cannot see it

dummy app to discuss it

library("shiny")
library("DT")
data(iris)

shinyApp(
  ui = fluidPage( DT::dataTableOutput("tabel")
  ),
  server = function(input,output,session){
      output$tabel <- DT::renderDataTable({datatable(iris, filter="top")})
  }
)

this one has just 5 columns so you can click x on each one and reset, if there are 50 columns that's not so easy - and without scrolling to the bottom of the screen you do not know if you are in filter or not

so what? flip filter='none', filter = 'top'? Or any other better way?

1
rstudio/DT#76 (from 2015) suggests that DT itself doesn't support a reset, the workaround suggested as to re-render the entire table (likely not a good solution for you with a large table). I don't know if anything has been done more recently.r2evans

1 Answers

3
votes

Ok, the answer was not overly difficult, set the proxy

proxy <-dataTableProxy('tabel')

and tie to a button

clearSearch(proxy)

it still leaves the nasty x in the search fields if you have CLEAR=TRUE in filter definition, but clears filters and refreshes the content without reloading it