Multiple dashtable update


app = Dash(__name__)

app.layout = html.Div([
    html.Div(id='live-update-nifty'),
    html.Div(dash_table.DataTable(id="output-3",
    columns=[
        {"name": i, "id": i} for i in finish_butterfly().columns],
    style_cell={'textAlign': 'center'},
    style_header={'backgroundColor': 'rgb(30, 30, 30)','color': 'white'},
    style_data={'backgroundColor': 'rgb(50, 50, 50)','color': 'white'},
    style_data_conditional=[{
    'if': {
        'row_index': 5,  # number | 'odd' | 'even'
        'column_id': 'strike'
    },
    'backgroundColor': 'hotpink',
    'color': 'white'
}])),
    html.Div(dash_table.DataTable(id="output-2",
    columns=[
        {"name": i, "id": i} for i in finish_butterfly().columns],
    style_cell={'textAlign': 'center'},
    style_header={'backgroundColor': 'rgb(30, 30, 30)','color': 'white'},
    style_data={'backgroundColor': 'rgb(50, 50, 50)','color': 'white'},
    style_data_conditional=[{
    'if': {
        'row_index': 5,  # number | 'odd' | 'even'
        'column_id': 'strike'
    },
    'backgroundColor': 'hotpink',
    'color': 'white'
}]),style={'display': 'inline-block',"padding": "20px"}),
    html.Div(dash_table.DataTable(id="output-1",
    columns=[
        {"name": i, "id": i} for i in finish_butterfly().columns],
    style_cell={'textAlign': 'center'},
    style_header={'backgroundColor': 'rgb(30, 30, 30)','color': 'white'},
    style_data={'backgroundColor': 'rgb(50, 50, 50)','color': 'white'},
    style_data_conditional=[{
    'if': {
        'row_index': 5,  # number | 'odd' | 'even'
        'column_id': 'strike'
    },
    'backgroundColor': 'hotpink',
    'color': 'white'
}]),style={'display': 'inline-block',"padding": "20px",'float': 'centre'}),
    html.Div(dash_table.DataTable(id="output-4",
    columns=[
        {"name": i, "id": i} for i in oi().columns],
    style_cell={'textAlign': 'center'}),style={'display': 'inline-block',"padding": "20px",'float': 'right'}),
    dcc.Interval(
            id='interval-component',
            interval=1800, # in milliseconds
            n_intervals=0),
    dcc.Interval(
            id='interval-component-2',
            interval=2500, # in milliseconds
            n_intervals=0)
])

@app.callback(Output('output-4', 'data'),Input('interval-component-2', 'n_intervals'))
def get_data(n):
    return oi().to_dict('records')
@app.callback(Output('output-3', 'data'),Input('interval-component-2', 'n_intervals'))
def get_data(n):
    return finish_butterfly().to_dict('records')
@app.callback(Output('output-2', 'data'),Input('interval-component', 'n_intervals'))
def get_data(n):
    return finish_butterfly().to_dict('records')
@app.callback(Output('output-1', 'data'),Input('interval-component', 'n_intervals'))
def get_data(n):
    return finish_butterfly().to_dict('records')
@app.callback(Output('live-update-nifty', 'children'),
              Input('interval-component', 'n_intervals'))
def get_data_1(n):
    return "NIFTY {}".format(datetime.now())
if __name__ == '__main__':
    app.run_server()



nothing is updating … how do i update all tables according to their specific intervals

hi @kiri
:wave: welcome to the community.

I see you’re returning oi().to_dict('records'). What is the oi(), Is that the function that houses your data set?

its a pandas dataframe …when i run a single dashtable …it runs and updates …but more than one dashtable it doesnt update …only header is seen

Have you tried returning multiple outputs for the same interval, and changing the name of the functions to be different?

@app.callback(
[Output('output-1', 'data'),
Output('output-2', 'data')],
Input('interval-component', 'n_intervals'))
def get_data_1(n):
    butterfly_data = finish_butterfly().to_dict('records')
    return [butterfly_data] * 2

@app.callback(
[Output('output-3', 'data'),
Output('output-4', 'data')],
Input('interval-component-2', 'n_intervals'))
def get_data_2(n):
    oi_data = oi().to_dict('records')
    butterfly_data = finish_butterfly().to_dict('records')
    return [butterfly_data, oi_data]

why are you using oi().columns vs just oi.columns ?

worked ( i had tried it earlier but it didnt for some reason , maybe i missed something ) … love you …

1 Like