Call back button doesn't work


The dft loop works fine, but the callback doesn’t “interrupt” the loop, the only debugged statement is the def plot_ticker_day(n_clicks):

Any suggestion ?

import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Output, Input
from pandas.core.frame import DataFrame
import plotly.graph_objects as go
import pandas as pd
from dash import Dash, dcc, html, Input, Output, State
from sqlalchemy import create_engine
import urllib
data = {'product_name': ['laptop', 'printer', 'tablet', 'desk', 'chair'],
        'price': [1200, 150, 300, 450, 200]
dft = pd.DataFrame(data)
app = dash.Dash(__name__)
for row in dft.itertuples():
    app.layout = html.Div([
        Output('ticker_day', 'figure'),
        Input('next_val', 'n_clicks')
    def plot_ticker_day(n_clicks):
        fig = go.Figure(data=[go.Scatter(x=[1, 2, 3], y=[4, 1, 2])])
        return fig
if __name__ == '__main__':


Welcome to the community!

Could you elaborate on what you are trying to get? Is your intention to update the Figure to use a new row from the dataframe each time you click on the button? If so, then you should not have a loop, but instead use n_clicks as index to get the specific row in the df… Right now you are just redefining the app layout and callback len(df) times.

1 Like

Hi @jlfsjunior ,

thank you so much , I was nearly getting crazy from lon long looking for a solution.

You have saved my evening right now !

Warm regards,