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

DataTable remove active_cell on data refresh

I’m using 1 data table to show multiple different data sets for an app I’m creating. I would rather do this and update the columns & data for each view instead of creating 1 data table for each data set I want to showcase.

One problem I’m facing is that if someone selects a cell in one “view” (read as 1 data table) that cell stays active when the data set changes, even if I pass None into active_cell. I’ve attached a short video of this behavior and a simple example. Any advice to ensure the active cell is removed when the data set is changed would be much appreciated!

import dash
import pandas as pd
import dash_table
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

a = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']), 'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df1 = pd.DataFrame(a)

b = {'three': pd.Series([10, 20, 30], index=['a', 'b', 'c']), 'four': pd.Series([10., 20., 30., 40.], index=['a', 'b', 'c', 'd'])}
df2 = pd.DataFrame(b)

app = dash.Dash(__name__)

app.layout = html.Div(
dcc.RadioItems( id='table_select', options=[
        {'label': 'df1', 'value': 'df1'},
        {'label': 'df2', 'value': 'df2'},
    Output('table', 'columns'),
    Output('table', 'data'),
    Output('table', 'active_cell')],
    [Input('table_select', 'value')]
def update_styles(value):
    if value == 'df1':
        df = df1 
        df = df2
    return [[{"name": i, "id": i} for i in df.columns],df.to_dict('records'),None]

if __name__ == '__main__':