1

I am trying to create a live updating graph with Plotly Dash with Python. Is there any way to delete the previous (first data input) data point and only plot the incoming one? This is my code:

import pandas as pd
import dash
import plotly.graph_objects as go
import dash_core_components as dcc
import dash_html_components as html


app = dash.Dash(__name__)
app.title = "Sistem de detectie al punctului mort"

def _create_fig():
    df = pd.read_csv('/home/pi/tflite1/csv_data_file.csv')
    df.columns=['x','y']
    return go.Figure(
        data=go.Scatter(
            x=df['x'],
            y=df['y'], mode = 'markers'))



app.layout = html.Div([
    dcc.Graph(
        id='g1',
        animate = True,
        figure=_create_fig()),
    dcc.Interval(
        id='interval-component',
        interval=1*1000, # in milliseconds
        n_intervals=0
    )
])
# 
# 
@app.callback(
    dash.dependencies.Output('g1', 'figure'),
    dash.dependencies.Input('interval-component', 'n_intervals')
    )

def refresh_data(n_clicks):
    return _create_fig()


if __name__ == "__main__":
    app.run_server(host='0.0.0.0', debug=True, port=8099)
    
Laura Rosu
  • 11
  • 1

0 Answers0