dreamRs / shinytreeview

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

Collapsing tree when search is used #3

Closed food-data-sci closed 3 years ago

food-data-sci commented 3 years ago

I am using treecheckInput and searchTreeview. When I open my app, the whole tree is expanded and all the items are in red. Is there a way to stop the tree from expanding before any value is typed into the search? collapse_before = TRUE works after something is typed into the search box but I would like the whole list to be collapsed before I do any search.

pvictor commented 3 years ago

Hello, Can you provide a minimal example ? The search seems to be triggered too early, maybe using req on search input will solve the issue.

Victor

food-data-sci commented 3 years ago

Using req as in the folowing worked!

  observeEvent(req(input$search),
               {
                 searchTreeview(
                   inputId = 'tree_id',
                   pattern = input$search,
                   ignore_case = TRUE,
                   exact_match = FALSE,
                   reveal_results = TRUE,
                   collapse_before = TRUE
                 )
               })

Thanks so much for an easy solution.