mercoledì 13 novembre 2024

Update Plotly Dash Csv

 

 


from dash import Dash, html, dcc, callback, Output, Input,State
import plotly.express as px
import pandas as pd

import sqlite3
df = pd.read_csv('./sir.csv')


#cnx = sqlite3.connect('winet.db')
#df = pd.read_sql_query("SELECT * FROM sensori", cnx)


app = Dash(__name__)

app.layout = [
html.H1(children='Sensori', style={'textAlign':'center'}),
html.Div([
dcc.Graph(id='graph-content',
figure={
'data': [
{'x': df.Data, 'y': df.Livello,
'type': 'line', 'name': '68'},
],
'layout': {
'title': 'Soggiacenza'
}
}),
dcc.Interval(
id='interval-component',
interval=2*1000,
n_intervals=0
)
])
]

@app.callback(
Output(component_id='graph-content', component_property='figure'),
Input('interval-component', 'n_intervals'), [State('graph-content', 'figure')]
)

def update_graph(n,figure):
df = pd.read_csv('./sir.csv')
figure['data'][0]['x'] = df.Data
figure['data'][0]['y'] = df.Livello
return figure


if __name__ == '__main__':
app.run(debug=True)

 

Nessun commento:

Posta un commento

Update Plotly Dash Csv

    from dash import Dash , html , dcc , callback , Output , Input , State import plotly . express as px import pandas as pd import...