I am trying to create a graph of sales using px.line. I create an initial plot and then repeatedly update the same one with forecasted data. The issue is that once I make the update, the line that was part of the previous forecast seems to remain although it doesn't point to any real data.
Couldn't figure out what to search for online. Is there a way to maybe reset the graph each time before plotting?
Relative beginner in this, Any help is appreciated.
app.layout = html.Div(children=[
html.Div("---- Overall"),
html.Div(
children=[
html.Div(children="ids"),
dcc.Dropdown(id='idx'),
]
),
html.Div("---- One"),
dcc.Input(
id="one",
# value=0,
type='number',
debounce=True,
placeholder="one",style=dict(width='10%')
),
dcc.Input(
id="two",
# value=0,
type='number',
debounce=True,
placeholder="two",style=dict(width='10%')
),
dcc.Input(
id="three",
# value=0,
type='number',
debounce=True,
placeholder="three",style=dict(width='10%')
),
dcc.Input(
id="four",
# value=0,
type='number',
debounce=True,
placeholder="four",style=dict(width='10%')
),
dcc.Input(
id="five",
# value=0,
type='number',
debounce=True,
placeholder="five",style=dict(width='10%')
),
dcc.Graph(
id='test',
# animate=True,
)
])
@app.callback(
Output('test', 'figure'),
[Input('idx', 'value'),Input('one', 'value'),Input('two', 'value'),Input('three', 'value')
,Input('four', 'value'),Input('five', 'value')])
def update_graph(idx,one,two,three,four,five):
# yy = input dataframe formatted as [year,month,qty] (other inputs handled here too)
fig = px.line(yy , x='month', y="qty",
color="year",
text='qty',
custom_data=['year'],
)
fig.update_layout(hovermode='x unified')
fig.update_traces(
hovertemplate="<br>".join([
"qty: %{y}",
])
)