Hello, Dash Community.
I am developing a data visualize program as a school project. Currently a have a simple layout: data file dropdown chooser, some checkboxes, a slider to choose the threshold and a graph, that depends on these properties. Code :
app.layout = html.Div([
# Choosing dataset
html.Label('Dataset'),
dcc.Dropdown(
id='dataset',
...
),
# With or without nonfrauds
html.Label('Nonfrauds'),
dcc.Checklist(
id='nonfrauds',
options=[
{'label': 'With Nonfrauds', 'value': 'Yes'},
],
values=['Yes']
),
# Highlights actual frauds
html.Label('Highlight actual frauds'),
dcc.Checklist(
id='highlight',
options=[
{'label': 'Highlight', 'value': 'Yes'},
],
values=[]
),
# Threshold slider
html.Label('Threshold'),
dcc.Slider( ...
),
html.Div(id="threshold-selected"),
# Update button
html.Button("Reload", id='reload'),
# Graph
html.Label("Graph"),
html.Div([
dcc.Graph(
id='graph',
figure=go.Figure(
data=get_markers(raw_data, actual_results=True),
layout=graph_layout,
),
),
], id="graph-container"),
], style={'width': '80%'})
Now, the graph takes data from the function that is tested and works OK. I use a callbacks on the button to update the graph, with respect to states of the properties. Here is the callback for the graph:
@app.callback(Output('graph-container', 'children'),
[Input('reload', 'n_clicks')],
[State('dataset', 'value'),
State('threshold', 'value'),
State('nonfrauds', 'values'),
State('highlight', 'values')]
)
def update_graph(n_clicks, dataset, threshold, with_non_frauds, highlight):
print(n_clicks)
new_data = pd.read_csv("data/" + dataset)
data = get_markers(new_data, threshold=threshold,
with_non_frauds=len(with_non_frauds) != 0,
actual_results=len(highlight) != 0)
return html.Div([
dcc.Graph(
id='graph',
figure=go.Figure(
data=data,
layout=graph_layout
)
)
], id="graph-container")
I run the server on my local, so it gets started and executed as following:
app = dash.Dash(“Semestralka”, external_stylesheets=external_stylesheets)
app.run_server(port=8051, debug=True)
The problem is, that when I start the server, it keeps on updating on its own, without me clicking the button. I’ ve added the
print(n_clicks)
line to see, if the update function actually gets called. And it turned out that yes, it does, even if I don’t press the button, so the console output is following:
127.0.0.1 - - [23/Dec/2018 11:37:23] "POST /_dash-update-component HTTP/1.1" 200 -
None
127.0.0.1 - - [23/Dec/2018 11:37:24] "POST /_dash-update-component HTTP/1.1" 200 -
None
127.0.0.1 - - [23/Dec/2018 11:37:28] "POST /_dash-update-component HTTP/1.1" 200 -
None
I would appreciate any clue or piece of advice. You can see my whole code on GitHub here: