Right now, it takes three to five seconds for my dashboard to produce the chart for the figure = argument of the dcc.Graph object. From then on, it is pretty fast because the chart updates over the course of the day and it’s quite fast. Even still, I wonder if it’s possible to load up the page first and then populate the chart. Right now, the URL for the chart is not available until after the three to five seconds is up. I’m wondering if I can host the url right away and then populate the graph.
This is using the wsgi server tool that comes out of the box with plotly hosted on the local machine
To make something not fire multiple times, you need to push the state of something that is setup to have some alteration, like an input that receives a 1 to show that it triggered already.
Didn’t think it would fire multiple times, because the id of the figure should not be changing…
Anyways, add toggle to your apps layout, in the output of the callback above toggle the element of that value to be FALSE or TRUE, depending on how you want to use it.
Then also in that callback, check for the state of it. If the state means it shouldn’t be triggered, then return dash.no_update to both outputs.
layout = html.Div([dcc.Graph(id='myChart'), dcc.Input(id=‘load_test’, type=‘checkbox’, value=TRUE)])
@app.callback (
Output('myChart','figure'), Output(‘load_test’, ‘value’), Input('myChart','id'), State(‘load_test’, ‘value’)
)
def updateChart(id, v):
If v:
return myFig(), not v
return dash.no_update, dash.no_update
This is really clever. Just to make sure I understand, this changes the dcc.store load test object to False after the first load and never runs again because there is a flag that says load test has to be true. Is that right?