Hello! I just created my first Plotly Dash app that takes data from a csv in real time and plots it to a graph. Is there any way I could delete the previous (first data input) data point and only plot the incoming one (last one added to the csv)?
This 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 = "Title"
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)