Hi,
I have a Dash project which read and plot data from a db in real-time.
I have tried to write a chained callback to control max_intervals and interval to enable the user to define both of them as input number! I have tried to define both as global variable to change them, but it does not work either!
any help is appreciated
my code:
waiting_time = 1000 #witing time for interval dash
max_time = 100 #100 defaulit
app.layout = html.Div([ ... dcc.Interval(id='update_Graph', interval = waiting_time , max_intervals = max_time),
dcc.Input(id = 'max_interval' , type="number", min=10, max=10000, step=50 , ), ... ])
@app.callback(Output('update_Graph' , 'n_intervals'),
Input('max_interval' , 'value'),
)
def update_maxtime(value):
global max_time
max_time = value
``` ....etc
Hi,
Are you returning any value in the callback function?
you should return value if you are not.
What is the error you are getting?
In this callback I do not return a value, but in the other callback which read and plot data I do return the figure!
I do not get any error. The callback is just running till the default max_intervals in code 100.
Not sure if i understood it correctly but here’s an example that illustrates of what i think you are trying to do:
from dash import Dash
from dash import html, Input, Output, State, dcc
app = Dash()
server = app.server
waiting_time = 1000 #witing time for interval dash
max_time = 10 #100 \defaulit
app.layout = html.Div([
dcc.Textarea(
id='textarea',
value='',
style={'width': '100%', 'height': 300},
),
dcc.Interval(id='update_Graph', interval = waiting_time , max_intervals = max_time),
dcc.Input(id = 'max_interval' , type="number", min=10, max=10000, step=50 , )])
@app.callback(Output('update_Graph' , 'max_intervals'),
Output('update_Graph' , 'n_intervals'),
Input('max_interval' , 'value'),
)
def update_maxtime(maxInterval):
return int(maxInterval),int(0)
@app.callback(Output('textarea' , 'value'),
Input('update_Graph' , 'n_intervals'))
def update_textarea(nInterval):
return str(nInterval)
if __name__ == "main":
app.run_server(debug=True)
1 Like
Sorry, I should have written bitter.
I want to enable the user to update the interval value and the max_intervals. That’s what I mint.
I have tried your first Callback, but it does not work also. The graph keep going after I set the max_intervalas!
not sure then, but can you try/confirm that my example as a standalone works. for changing the max_interval? you need to toggle it with the up and down arrows in the input field,
The interval time is just an additional input and output on the property.
to make it work for your code you need to share more of your code as an MRE which we can run and test ourselves. Its hard to say anything about why that part is not working otherwise
Hi, sorry for the late answer.
Also, I have two callbacks, one to update the max_time(max_intervals) as global variable and the another to use the updated mx_time! I want to enable the user to define the intervals and max_intervals by inserting a number as input!
that’s my target 
that’s more from the code
waiting_time = 1000 #witing time for interval dash
max_time = 100 #100 defaulit
app.layout = html.Div([ ... dcc.Interval(id='update_Graph', interval = waiting_time , max_intervals = max_time),
dcc.Input(id = 'max_interval' , type="number", min=10, max=10000, step=50 , ),
dcc.Dropdown(id = 'dropdown' , ) ... ])
@app.callback(Output('update_Graph' , 'n_intervals'),
Input('max_interval' , 'value'),
)
def update_maxtime(value):
global max_time
max_time = value
##Callback to mesuremetn and update the graph
@app.callback(Output('live-graph', 'figure'),
[Input('update_Graph' , 'n_intervals'),
Input('switch' , 'on'),
Input('dropdown', 'value')
])
def updating_graph(n , on, dropdown):
data = [] #data for graph as array to append data for each dropdown value
layout = go.Layout()
### hte data sampling
figure = go.Figure({'data' : data , 'layout' : layout})
figure
return figure