# Triggering callback from within Python

**URL:** <https://community.plotly.com/t/triggering-callback-from-within-python/23321>\
**Category:** Dash Python\
**Created:** [May 10, 2019, 4:41pm UTC](https://community.plotly.com/t/triggering-callback-from-within-python/23321 "2019-05-10T16:41:14Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![narragansett](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@narragansett](https://community.plotly.com/u/narragansett)\
**Post date:** [July 8, 2019, 1:40pm UTC](https://community.plotly.com/t/triggering-callback-from-within-python/23321/6 "2019-07-08T13:40:44Z")

</div>

I implemented this mechanism with a dash component, to test/play with. [Here it is](https://drive.google.com/file/d/13WeuwPrhKPGRVZBAZCeBX3MtbvbNJOWZ/view?usp=sharing) – 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')

```

![Screenshot%20from%202019-07-08%2008-38-46](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/8/83b0aff1ff13400ac05be986d9168c737eece490.png)

---

_[View the full topic](https://community.plotly.com/t/triggering-callback-from-within-python/23321)._
