0

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}",
    ])
)

-before Before

-after After

  • 1
    With all this information, I can't advise you. Can you provide full code and sample data? – r-beginners Dec 11 '22 at 11:21
  • 2
    Can you share your Dash app. layout? – Mr.Slow Dec 11 '22 at 16:24
  • Updated with app.layout. @r-beginners I apologize, full code might not be possible right now. From my understanding, its very likely a mistake related to how i'm plotting as the data structures going through between updates are the same. – Pramod Anantha Dec 11 '22 at 20:19
  • @PramodAnantha would it be possible to share the callback function in your dash app where you update the data in your figure? that is likely where the error is occurring – Derek O Dec 11 '22 at 22:28
  • @DerekO Updated with entire callback – Pramod Anantha Dec 12 '22 at 05:45

0 Answers0