Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuzzy search box widget with `Shiny` in R?

Has anyone created or seen a Shiny app featuring search box widget giving contextual suggestions as you type, based on fuzzy matching?

Bloomberg terminal uses it, Google uses it. One of the possible underlying technologies is called elasticsearch.org 's fuzzy query, with two R implementations:

  1. duncantl/RElasticSearch
  2. ropensci/elastic

Search box filter coming with the basic Shiny's datatable doesn't quite cut it.

If this is something yet to be integrated with Shiny, any rough guide how to build it? I suspect it would be extremely useful on biggish tables (or documents) with lots of text, when you want to look for specific rows, without displaying the full table.

like image 839
Daniel Krizian Avatar asked Jul 05 '14 19:07

Daniel Krizian


2 Answers

Maybe a combobox could be fed a list from stringdist() that would compare the input string against a known list and provide the items with the 10 items with the shortest string distance. Would probably be very inefficient with huge lists, but the algorithm is fairly fast when comparing against a short list.

One of the stringdist methods even compares based on how words are pronounced, not sure if that's useful.

like image 71
Amit Kohli Avatar answered Nov 04 '22 09:11

Amit Kohli


If you are using selectInput(), then you can set the parameter "choices" to a vector, and the contents of that vector will appear as the user types. The problem with this is that the user cannot select anything that is not contained in the vector.

UI:

selectInput(
    "reference_name", label = h3("Selection"), choices = vector_of_search_possibilities, selectize = TRUE, selected = "Alabama"
  )

SERVER: reference this object using

input$reference_name
like image 3
Hannah Murphy Avatar answered Nov 04 '22 10:11

Hannah Murphy