Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 webinar.

Conditional formatting of a substring in cells' text


I have the following code that highlights the whole text of any cell if it contains a search substring. Is there a way to only highlight (format) the substring in the cells’ text (similar to search highlighting)?

@app.callback([Output('datatable','data') ,

                Output('datatable', 'style_data_conditional')


                [Input('input2', 'n_clicks')],

                [State('input1', 'value')])

def update(clicks,val):

    # TODO  highlight only matching sub-string

    df = filter(val, clicks)

    if val == '':

        return df.to_dict('records'), []


        return df.to_dict('records'), [


                    'if': {

                        'filter_query': '{{{}}} contains "{}"'.format(col, val),

                        'column_id': col


                    'color': 'tomato',


                } for col in df.columns