I have a callback which will be working and then just stop updating altogether, not sure why this is happening at all. Below is the code, I have took this out of my main app into a little test environment.
I have tried adding a button and changing the callback however I still end up with issues.
The callback/pie graph will work initially, but then it will just stop working, I could have moved on and just been adding some comments to the code, not touching it, and then it stops working.
#Imports
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 *
#Dash - App Layout
#Init Dash App
app = dash.Dash(external_stylesheets=[dbc.themes.LUX])
#app.config['suppress_callback_exceptions'] = True
#Producing Data for Month Sales Breakdown
year = "2020"
month = "February"
stypemonth = get_stype_month_data(year, month)
smpiefig = px.pie(stypemonth.to_dict(), values='Value', names='SaleType')
#Webpage Layout
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')),
]
)
#This callback sometimes works? Need attention
@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
#Starting the App
if __name__ == '__main__':
app.run_server(debug=True)
And here is the code get get_stype_month_data() just pulling from a SQL DB, it works fine for just printing the data.
#SQL to get total of each sale type per month
def get_stype_month_data(month, year):
con = sqlite3.connect(str(DBFILE))
stypemdata = pd.read_sql_query("SELECT Category as SaleType, SUM(SValue) as Value FROM Figures WHERE Type='Sale' AND Month=? AND TaxYear=? GROUP BY Category", con, params={month, year})
return stypemdata
Any help would be appreciated!