Hi,
I have a problem with the using of background callbacks.
the project is to read data from and store it into SQLite that is the background callback
the second callback it to read from db and plot it in real time.
I am trying the background because of the use of dcc.Interval will not allow the user to do anything but to wait for the plot to finish to keep the interval timing accuracy.
The call count of the callback stays by 0 !
has anyone any idea to help ?
Thank you
My code:
celery_app = Celery(__name__, broker="redis://localhost:6379/0", backend="redis://localhost:6379/1")
background_callback_manager = CeleryManager(celery_app)
@dash.callback(Output(component_id='background_store', component_property='data'),
Input(component_id='background_interval', component_property='n_intervals'),
Input(component_id='switch', component_property='on'),
Input(component_id='dropdown', component_property='value'),
background=True,
manager=background_callback_manager,
)
def background_acquisition(n , on, dropdown, ):
ADC_Value = ADC.ADS1256_GetAll()
data = [] #array for figure then append data for each dropdown value
if on == False: #switch on/off
no_update
return no_update
else:
layout = go.Layout( xaxis=dict( title="Zeit [sec]" ), yaxis=dict( title="AD Signal [counts]" ) )
time_stamp = timing
conn = sqlite3.connect(messen)
curs = conn.cursor()
curs.execute("INSERT INTO time (epoch , timing) VALUES ( ?, ?)", (unix_time , time_stamp))
conn.commit()
increase_time()
df_time = pd.read_sql_query("SELECT zeit FROM time ORDER BY zeit ASC ", conn)
last_row_time = df_time.iloc[:n,:]
curs.execute("INSERT INTO k1 (k1 ) VALUES (?)", (([(ADC[0])])))
conn.commit()
df1 = pd.read_sql_query("SELECT * FROM k1 ", conn)
row1 = df1.iloc[:n,:]
data.append(go.Scatter(x = asarray(last_row_time[df_time.columns[0]]) , y = asarray(row1[df1.columns[0]]),))
update_timing()
global x2 #update x2 and gloabe waiting time for interval to subtract process time
x2 = monotonic() - x1
global waiting_time
waiting_time = 1 - x2
figure = go.Figure({'data' : data , 'layout' : layout})
figure
return figure
.... #
#update x2 and gloabe waiting time for interval and subtract process time from waiting time to keep waiting time 1 sec
#callback graphing
@app.callback(Output(component_id='live-graph', component_property='figure'),
Input(component_id='update_Graph', component_property='n_intervals'),
Input(component_id='switch', component_property='on'),
Input(component_id='dropdown', component_property='value'),
)
def update_graph(n):
data = []
layout = go.Layout( xaxis=dict( title="Zeit [sec]" ), yaxis=dict( title="AD Signal [counts]" ) )
conn = sqlite3.connect(messen)
curs = conn.cursor()
df_time = pd.read_sql_query("SELECT timing FROM time ORDER BY timing ASC ", conn)
last_row_time = df_time.iloc[:n,:]
df1 = pd.read_sql_query("SELECT * FROM k1 ", conn)
row1 = df1.iloc[:n,:]
data.append(go.Scatter(x = asarray(last_row_time[df_time.columns[0]]) , y = asarray(row1[df1.columns[0]]), ))
figure = go.Figure({'data' : data , 'layout' : layout})
figure
return figure