Python Forum
Call back doesn't work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: Call back doesn't work (/thread-37339.html)



Call back doesn't work - michel77777 - May-29-2022

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([
        html.H3(row.product_name),
        html.H3(row.price),
        html.Button("Next",id='next_val'),
        dcc.Graph(id='ticker_day')
    ])
    @app.callback(
        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__':
    app.run_server(debug=False)