Search code examples
pythondataframedatatableplotly-dash

Dash - search and display results in datatable


I have a dataframe of patient records as rows and various features as columns.

I'd like to be able to search through this dataframe based on one feature and display the rows that correspond to that search in a Dash DataTable.

What's the best way to do this? I understand DataTables have their own native filtering function, but is it possible to filter based on a user-entered value from an input field or dropdown value?


Solution

  • Yes, completely doable. You need a callback for that. It will take as input the value of the dropdown, or input field, and its output will be the data prop for the table component. Inside the callback, you can filter your dataframe based on the input value.

    Depending on where you load the data for the table from, you may want to put the original, unfiltered data in something like a dcc.Store and pass that to your callback as a state value, to avoid having to make network or database calls repeatedly.