rstudio / DT

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

Update numeric slider values on updateSearch #1111

Closed mikmart closed 5 months ago

mikmart commented 5 months ago

Fixes #1110.

library(shiny)
library(DT)

ui <- fluidPage(
  actionButton("set_search", "Set column search"),
  tags$hr(),
  DTOutput("iris")
)

server <- function(input, output, session) {
  output$iris <- renderDT(
    datatable(iris, filter = "top")
  )

  proxy <- dataTableProxy("iris")
  observeEvent(input$set_search, {
    updateSearch(proxy, keywords = list(columns = c("", "5.0 ... 6.0")))
  })
}

shinyApp(ui, server)

image

CLAassistant commented 5 months ago

CLA assistant check
All committers have signed the CLA.

mikmart commented 5 months ago

I changed the approach to use a custom event updatesearch so that each search field can handle updates from R as it wishes. This was to avoid the unnecessary searchColumn() call while also bypassing the input throttling for character columns.

Would you have another look @yihui? In particular I'm wondering if the custom event name should be namespaced somehow.

mikmart commented 5 months ago

Yeah that makes sense. I can pivot to that approach.

mikmart commented 5 months ago

Ready for a review again @yihui.