Spaces:
Sleeping
Sleeping
Esmaeilkiani
commited on
Commit
•
90ccab5
1
Parent(s):
af2682b
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
from plotly.subplots import make_subplots
|
5 |
+
import dash
|
6 |
+
from dash import dcc, html, Input, Output, State
|
7 |
+
import dash_bootstrap_components as dbc
|
8 |
+
|
9 |
+
# Load CSV into DataFrame
|
10 |
+
df = pd.read_csv('data.csv')
|
11 |
+
|
12 |
+
# List of unique farm names for the dropdown
|
13 |
+
farm_names = df['Farm Name'].unique()
|
14 |
+
|
15 |
+
# Initialize the Dash app
|
16 |
+
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
17 |
+
|
18 |
+
app.layout = dbc.Container([
|
19 |
+
dbc.Row([
|
20 |
+
dbc.Col([
|
21 |
+
html.H1("Farm Height Dashboard", className='text-center'),
|
22 |
+
dcc.Dropdown(
|
23 |
+
id='farm-dropdown',
|
24 |
+
options=[{'label': name, 'value': name} for name in farm_names],
|
25 |
+
placeholder='Select a farm...'
|
26 |
+
),
|
27 |
+
html.Div(id='output-container')
|
28 |
+
], width=12)
|
29 |
+
]),
|
30 |
+
dbc.Row([
|
31 |
+
dbc.Col([
|
32 |
+
dcc.Graph(id='height-histogram')
|
33 |
+
], width=12)
|
34 |
+
])
|
35 |
+
], fluid=True)
|
36 |
+
|
37 |
+
@app.callback(
|
38 |
+
Output('height-histogram', 'figure'),
|
39 |
+
Output('output-container', 'children'),
|
40 |
+
Input('farm-dropdown', 'value')
|
41 |
+
)
|
42 |
+
def update_graph(selected_farm):
|
43 |
+
if selected_farm is None:
|
44 |
+
return go.Figure(), "Please select a farm."
|
45 |
+
|
46 |
+
# Filter data based on selected farm
|
47 |
+
filtered_df = df[df['Farm Name'] == selected_farm]
|
48 |
+
|
49 |
+
# Prepare 3D surface data
|
50 |
+
weeks = np.arange(1, 19)
|
51 |
+
heights = filtered_df.iloc[:, 1:19].values # Adjust for your actual data structure
|
52 |
+
|
53 |
+
fig = make_subplots(rows=1, cols=1, specs=[[{'type': 'surface'}]])
|
54 |
+
|
55 |
+
fig.add_trace(
|
56 |
+
go.Surface(
|
57 |
+
z=heights,
|
58 |
+
x=weeks,
|
59 |
+
y=filtered_df['Farm Name'].values,
|
60 |
+
colorscale='Viridis'
|
61 |
+
)
|
62 |
+
)
|
63 |
+
|
64 |
+
fig.update_layout(
|
65 |
+
title=f'Height Histogram for {selected_farm}',
|
66 |
+
scene=dict(
|
67 |
+
xaxis_title='Week',
|
68 |
+
yaxis_title='Farm Name',
|
69 |
+
zaxis_title='Height'
|
70 |
+
)
|
71 |
+
)
|
72 |
+
|
73 |
+
return fig, f"Displaying data for: {selected_farm}"
|
74 |
+
|
75 |
+
if __name__ == '__main__':
|
76 |
+
app.run_server(debug=True)
|