Hello. I use data_table with 26 rows of user inputs as inputs to a keras model. The table is editable, and is pre-populated using suggested values from to ease the pain of data entry.
Unfortunately, the data_table callback is triggered and the model is run every time the user inputs a new value in the table. I tried using a button as a trigger, but every entry on the datatable initiates a callback no matter what I do. The button callback trigger works too, but overall, my code can’t distinguish between a button trigger and a new data point trigger in the data_table.
Is there a way to ignore the datatable callback, or a different way to load data into a dash that doesn’t require data_table?
Karl
Here is my code (well part of it, any way)
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
html.H1('LGR Predictor'),
dcc.Tabs(id="lgr_tabs", value='tab-1', children=[
dcc.Tab(label='Tab One', value='tab-1', children=[
dash_table.DataTable(
id='input_table',
columns=[
{"name": ["Feature"], "id": "feature"},
{"name": ["Rank"], "id": "rank", "editable": False },
{"name": ["Value"], "id": "value", "editable": True},
],
data = [
{'feature':'PR Avg_imp','value': 0.24, 'rank': 1},
{'feature':'YM Avg_imp', 'value': 61, 'rank': 9},
{'feature':'API_imp', 'value': 45, 'rank': 3}]
),
html.Div([
html.Button(id='submit_button', n_clicks=0, children='Submit'),
html.Div(id='output_state'),
],style={'text-align': 'center'}),
]),
dcc.Tab(label='Tab Two', value='tab-2'),
]),
html.Div(id='model_graphs') # this is the the content for the tab as a child
])
@app.callback(Output('model_graphs', 'children'), # the output content for the tab as a child
[Input('submit_button', 'n_clicks')],
Input('lgr_tabs', 'value'), #keeps track of which tab is active
Input('input_table', 'data'), # the data from the input table
State=[State('input_table', 'value')],
)
def render_content(n_clicks, tab, rows, state):
if tab == 'tab-1':
print(rows)
figure0 = html.Div([
html.H3('Predictor Inputs'),
dcc.Graph(
figure={
'data': [{
'x': [1, 2, 3],
'y': [3, 1, 2],
'type': 'bar'
}]
}
),
])
return figure0
elif tab == 'tab-2':
figure0 = html.Div([
html.H3('Tab content 2'),
dcc.Graph(
id='graph-2-tabs-dcc',
figure={
'data': [{
'x': [1, 2, 3],
'y': [5, 10, 6],
'type': 'bar'
}]
}
)
])
return figure0
if __name__ == '__main__':
app.run_server(debug=False)