Hello, there are two datables with and without callback in provided example.
Checkbox "1" is set by default
Check "select all" in both datatables
Check/uncheck "0" checkbox to see difference
# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_table_experiments as dte
import pandas as pd
import numpy as np
MAGIC_NUM = 5
dfs = []
for x in range(MAGIC_NUM):
df = pd.DataFrame(np.random.randn(5, 2), columns=['df', 'value'])
df['df'] = x
dfs.append(df)
dfs = pd.concat(dfs)
Hello, there are two datables with and without callback in provided example.
MAGIC_NUM = 5 dfs = [] for x in range(MAGIC_NUM): df = pd.DataFrame(np.random.randn(5, 2), columns=['df', 'value']) df['df'] = x dfs.append(df) dfs = pd.concat(dfs)
app = dash.Dash() app.scripts.config.serve_locally = True app.layout = html.Div([ dcc.Checklist( id='check-df', options=[{'label': x, 'value': x} for x in range(MAGIC_NUM)], values=[1] ), html.Div( id='dummy' ), html.Div([dte.DataTable( id='datatable_1', rows=dfs.to_dict('records'), columns=dfs.columns, row_selectable=True )], style={'width': '49%', 'display': 'inline-block'}), html.Div([dte.DataTable( id='datatable_2', rows=dfs.to_dict('records'), columns=dfs.columns, row_selectable=True )], style={'width': '49%', 'display': 'inline-block'}), ])
@app.callback( Output('datatable_1', 'rows'), [Input('check-df', 'values')]) def change_df(values): return dfs[dfs['df'].isin(values)].to_dict('records')
@app.callback( Output('datatable_2', 'rows'), [Input('check-df', 'values')]) def change_df(values): return dfs[dfs['df'].isin(values)].to_dict('records')
@app.callback( Output('dummy', 'children'), [Input('datatable_1', 'rows'), Input('datatable_1', 'selected_row_indices')]) def on_select(rows, selected_row_indices): return None
if name == 'main': app.run_server()