dreamRs / shinytreeview

Hierarchical tree input for Shiny apps
GNU General Public License v3.0
41 stars 8 forks source link

searchTreeview behaves strangely #16

Open flash0926 opened 1 week ago

flash0926 commented 1 week ago

According to the sample code, after adding this search function on the server side. By default, all levels will be expanded and all countries will meet the conditions. searchTreeview( inputId = "country", pattern = input$search, reveal_results = TRUE ) I think it is the pattern field. When no search value is entered, the passed pattern is "", and the code will think that this "" can be matched by any string. I have tried to set it to NA or NULL, but the performance is abnormal. Setting it to NA is the same as setting it to "" Setting it to NULL, although it meets expectations in the default state. However, once a search is performed, the performance status will not be refreshed after resetting to NULL. How to deal with this?

pvictor commented 6 days ago

Hello,

I added `` function to clear the the search, so now you can check that the search pattern is truthy and then search for it or clear the search, e.g. :

observeEvent(input$search, {
  if (isTruthy(input$search)) {
    searchTreeview(
      inputId = "country",
      pattern = input$search,
      reveal_results = TRUE
    )
  } else {
    clearSearchTreeview("country")
    collapseTreeview("country")
  }
})
flash0926 commented 1 day ago

Thanks!