data viz

Rhandsontable search functionality

Do you need to edit some data in your webapplication? If you are building an R shiny app, you can use the Rhandsontable package for it. I have used it a couple of times now and though there are some points for improvement for this package, it could be a good solution for you. In this blog I will describe about an improvement I have made for this package: search functionality. Since I am making money by using the great (mostly free) products of the R community, I am glad to give something back!

The rhandsontable package is based on the javascript handsontable library.  The R package contains bindings to this library to make specific functionality available for an R user.  Some of the functions are: making certain rows or columns readonly, highlight cells and turning the table into a heatmap. The javascript library did contain the search functionality already for some time but it was not available in the R package. Since the description of how the search functionality works is pretty good, it was not hard to implement it in the R binding. Basically these things had to be done

  • add a parameter to the rhandsontable constructor to indicate if searching should be allowed
  • add a textfield where a user can enter text
  • add an event handler that reads the data and updates the table

Please see my pull request for the code changes. The animated gif below shows a simple example of the search functionality. The data in the table is the life expectancy for all countries split by gender. To see quickly which countries belong to America, start typing in Americas. You will see that the match doesn’t need to be complete, if part of the search string matches with a cell, that cell will be highlighted.

Rhandsontable search functionality