I implemented this mechanism with a dash component, to test/play with. Here it is – you can modify any dash component directly within python, for example:
change('slider', {'value': 10})
Here, the slider with id=‘slider’ would update and any callbacks would be called.
It uses flask socketio. You put the ‘sockettest’ component in the layout and the right things will happen with the socket connection.
app.layout = html.Div([
sockettest.sockettest(),
html.Progress(id='progress', max=10, value=0),
dcc.Slider(id='slider', value=0, min=0, max=10, step=1),
html.Div(id='divspace')
])
def change(id, val):
socket.emit('call', {'id': id, 'val': val})
def timerCallback():
Timer(1.0, timerCallback).start()
change('slider', {'value': timerCallback.i})
change('progress', {'value': timerCallback.i})
change('divspace', {'children': 'hello ' + str(timerCallback.i)})
timerCallback.i += 1;
if timerCallback.i>10:
timerCallback.i = 0
timerCallback.i = 0
if __name__ == '__main__':
timerCallback()
socket.run(server, debug=False, port=5000, host='0.0.0.0')