I have a callback which sometimes works and sometimes doesn’t, not really sure whats going on, after a page refresh the callback will suddenly not work. I’ve took it into it’s own environment so that I can see if it’s anything else in the app causing the issue, but I still get the inconsistency. Below is the code.
>
>
> import pandas as pd
>
> import sqlite3
>
> import pathlib
>
> import dash
>
> from dash.dependencies import Input, Output, State
>
> import dash_bootstrap_components as dbc
>
> import dash_core_components as dcc
>
> import dash_html_components as html
>
> import dash_table as dt
>
> from plotly import tools
>
> import plotly.graph_objs as go
>
> import plotly.express as px
>
> import base64
>
> import cufflinks as cf
>
> from SQL import *
>
>
> app = dash.Dash(external_stylesheets=[dbc.themes.LUX])
>
>
> year = "2020"
>
> month = "February"
>
> stypemonth = get_stype_month_data(year, month)
>
> smpiefig = px.pie(stypemonth.to_dict(), values='Value', names='SaleType')
>
>
> app.layout = html.Div(
>
> [
>
> dbc.Row(dbc.Col(html.P(""))),
>
> dbc.Row(dbc.Col(dcc.Dropdown(
>
> id='sales-month-dropdown',
>
> options=[{'label':'January', 'value':'January'},{'label':'February', 'value':'February'}],
>
> value='January'
>
> ))),
>
> dbc.Row(dbc.Col(dcc.Dropdown(
>
> id='sales-year-dropdown',
>
> options=[{'label':'2020/21', 'value':'2020'},{'label':'2021/22', 'value':'2021'}],
>
> value='2020'
>
> ))),
>
> dbc.Col(dcc.Graph(figure=smpiefig,id='sales-stypemonthpie')),
>
> ]
>
> )
>
>
> @app.callback(
>
> Output("sales-stypemonthpie","figure"),
>
> [Input("sales-month-dropdown", "value"),
>
> Input("sales-year-dropdown", "value")]
>
> )
>
> def update_sales_smpie(selected_month, selected_year):
>
> newstypemonth = get_stype_month_data(selected_month, selected_year)
>
> newsmpiefig = px.pie(newstypemonth.to_dict(), values='Value', names='SaleType')
>
> print(selected_month + selected_year)
>
> return newsmpiefig
>
>
> if __name__ == '__main__':
>
> app.run_server(debug=True)
> Blockquote
Any help would be appreciated!