Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shiny DT datatable - reset filters

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?

like image 826
Slav Avatar asked Nov 02 '25 08:11

Slav


1 Answers

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

like image 196
Slav Avatar answered Nov 03 '25 22:11

Slav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!