Code/Dash_app.py gelöscht
parent
907047e889
commit
758d7964b5
113
Code/Dash_app.py
113
Code/Dash_app.py
|
@ -1,113 +0,0 @@
|
|||
import pandas as pd
|
||||
from dash import Dash, html, dash_table, dcc, callback
|
||||
from dash.dependencies import Input, Output
|
||||
import plotly.express as px
|
||||
from datetime import datetime
|
||||
import plotly.graph_objects as go
|
||||
|
||||
df = pd.read_csv('Data.csv')
|
||||
df_reversed = df.iloc[::-1]
|
||||
|
||||
pressure = df['Barometric Pressure'].iloc[-1]
|
||||
humidity = df['Humidity'].iloc[-1]
|
||||
|
||||
|
||||
app = Dash(__name__)
|
||||
|
||||
app.layout = html.Div([
|
||||
html.H1('Wetter', style={'textAlign': 'center'}),
|
||||
|
||||
html.Div([
|
||||
dcc.Graph(id='temperature-indicator'),
|
||||
dcc.Graph(id='pressure-indicator'),
|
||||
dcc.Graph(id='humidity-indicator')
|
||||
], style={'display': 'flex'}),
|
||||
dcc.RadioItems([{'label': 'Temperature', 'value': 'Temperature'},
|
||||
{'label': 'Barometric Pressure', 'value': 'Barometric Pressure'},
|
||||
{'label': 'Humidity', 'value': 'Humidity'}],
|
||||
inline=True,
|
||||
id='radioitem',
|
||||
value='Barometric Pressure'),
|
||||
dcc.Graph(id='Pressure'),
|
||||
dash_table.DataTable(
|
||||
id='wetter',
|
||||
data=df_reversed.to_dict('records'),
|
||||
columns=[{'name': i, 'id': i} for i in df.columns],
|
||||
sort_mode='single',
|
||||
sort_action='native',
|
||||
style_cell={'textAlign': 'center'}),
|
||||
dcc.Interval(
|
||||
id='update',
|
||||
interval=10000,
|
||||
n_intervals=0)
|
||||
])
|
||||
|
||||
|
||||
@callback(Output('temperature-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def temp_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
temperature = df['Temperature'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=temperature,
|
||||
title={'text': "Temperature (°C)"},
|
||||
gauge={'axis': {'range': [-20, 40]},
|
||||
'bar': {'color': 'red'}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('pressure-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def pressure_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
pressure = df['Barometric Pressure'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=pressure,
|
||||
number={'valueformat': '.2f'},
|
||||
title={'text': "Barometric Pressure"},
|
||||
gauge={'axis': {'range': [500, 1300]}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('humidity-indicator', 'figure'),
|
||||
Input('update', 'n_intervals'))
|
||||
def temp_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
humidity = df['Humidity'].iloc[-1]
|
||||
figure = go.Figure(
|
||||
go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=humidity,
|
||||
title={'text': "Humidity"},
|
||||
gauge={'axis': {'range': [0, 100]},
|
||||
'bar': {'color': 'blue'}}))
|
||||
return figure
|
||||
|
||||
|
||||
@callback(Output('wetter', 'data'),
|
||||
Input('update', 'n_intervals'))
|
||||
def get_update(n):
|
||||
df = pd.read_csv('Data.csv')
|
||||
df_reversed = df.iloc[::-1]
|
||||
return df_reversed.to_dict('records')
|
||||
|
||||
|
||||
@callback(Output('Pressure', 'figure'),
|
||||
Input('update', 'n_intervals'),
|
||||
Input('radioitem', 'value'))
|
||||
def update_graph(n, x):
|
||||
df = pd.read_csv('Data.csv')
|
||||
today = datetime.today().date()
|
||||
df_filtered = df.tail(60).copy()
|
||||
df_filtered['Date'] = pd.to_datetime(df_filtered['Date'], dayfirst=True)
|
||||
df_filtered = df_filtered[df_filtered['Date'].dt.date == today]
|
||||
fig = px.line(df_filtered, x='Time', y=x)
|
||||
return fig
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run_server(debug=True)
|
Loading…
Reference in New Issue