Python in real time

I would like to make a graph in real time on plotly with a Python program

import plotly
import random
from plotly.graph_objs import Scatter, Layout
valeurx = []
valeury = []
while (i<10):

“data”: [
Scatter(x=valeurx, y= valeury)
“layout”: Layout(
title=“evolution de la consigne et distance”

I tested this program but the problem is that it only appears at the end of the program otherwise it opens me a window by data and it is not on the internet

You need to create a Dash app, not just a plotly graph, look at the Dash documentation: and specifically live updates:

I’ve created this code in the past of a very simple example of live updating a graph:

import random

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate

external_stylesheets = ['']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    html.H1(children='Hello World!', id='first'),
    dcc.Interval(id='timer', interval=1000),
                'data': [
                    {'x': [1, 2, 3],
                     'y': [4, 1, 2],
                     'type': 'bar', 'name': 'SF'},
                    {'x': [1, 2, 3],
                     'y': [2, 4, 5],
                     'type': 'bar', 'name': 'Montréal'},
                'layout': {
                    'title': 'Dash Data Visualization'

@app.callback(output=Output('example-graph', 'figure'),
              inputs=[Input('timer', 'n_intervals')])
def update_graph(n_clicks):
    return {
                'data': [
                    {'x': [1, 2, 3],
                     'y': [random.randint(0, 10) for x in range(3)],
                     'type': 'bar', 'name': 'SF'},
                    {'x': [1, 2, 3],
                     'y': [random.randint(0, 10) for x in range(3)],
                     'type': 'bar', 'name': 'Montréal'},
                'layout': {
                    'title': 'Dash Data Visualization'

if __name__ == '__main__':

It’s a modified version of the tutorial bar graph with live updates built in to it.

1 Like

thank you but when I started a program there was a long error message the same as when I tried the one from the dash guide:

Running on
Debugger PIN: 828-777-804
Traceback (most recent call last):
File “C:/Users/matth/AppData/Local/Programs/Python/Python37-32/”, line 109, in
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\dash\”, line 1318, in run_server
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flask\”, line 938, in run
cli.show_server_banner(self.env, self.debug,, False)
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\flask\”, line 629, in show_server_banner
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\click\”, line 218, in echo
file = _default_text_stdout()
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\”, line 675, in func
rv = wrapper_func()
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\”, line 436, in get_text_stdout
rv = _get_windows_console_stream(sys.stdout, encoding, errors)
File “C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\”, line 295, in _get_windows_console_stream
func = _stream_factories.get(f.fileno())
io.UnsupportedOperation: fileno

can you tell me where I wrong?

It’s a weird error but I think it’s because you’ve created your Python file in a location that you need system privileges to have lock access to the file.

Either create your python script somewhere else or try running it without debug=True which shouldn’t then need lock access to the file, e.g.:


I recreated the script in my documents and even without the “debug = True” there is the error

I Googled your error and found this trail of Stackoverflow questions:

Are you trying to run this in IDLE Python IDE or some other similar tool? If so try running it from the command line:


thank you very much it works well it was enough to activate it in the command prompt with the command:
for example if you have put your file in your documents take the commande:
python C:\Users\matth\Documents\9-PYTHON\