Esmaeilkiani commited on
Commit
d851ab7
·
verified ·
1 Parent(s): bdb918f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import plotly.express as px
3
+ from dash import Dash, dcc, html, Input, Output
4
+
5
+ # بارگیری داده از فایل CSV
6
+ df = pd.read_csv('/content/گروهبندی مزارع کراپ لاگ 1403.csv') # فایل CSV خود را وارد کنید
7
+
8
+ # ایجاد اپلیکیشن Dash
9
+ app = Dash(__name__)
10
+
11
+ # تعریف لیست گزینه‌ها برای انتخاب نام ستون
12
+ column_options = [{'label': col, 'value': col} for col in df.columns]
13
+
14
+ # طراحی لایه‌های اپلیکیشن
15
+ app.layout = html.Div([
16
+ html.H1('Zali Ai - اداره زراعت و کنترل محصول'),
17
+ dcc.Dropdown(
18
+ id='column-dropdown',
19
+ options=column_options,
20
+ value=df.columns[0] # مقدار پیش‌فرض برای انتخاب ستون
21
+ ),
22
+ dcc.Graph(id='main-graph')
23
+ ])
24
+
25
+ # تعریف callback برای به‌روزرسانی گراف
26
+ @app.callback(
27
+ Output('main-graph', 'figure'),
28
+ [Input('column-dropdown', 'value')]
29
+ )
30
+ def update_graph(selected_column):
31
+ fig = px.bar(df, x=selected_column)
32
+ fig.update_layout(
33
+ title=f'توزیع {selected_column}', # عنوان گراف
34
+ xaxis_title=selected_column, # نام محور افقی
35
+ yaxis_title='تعداد ردیف‌ها', # نام محور عمودی
36
+ barmode='group', # نوع نمودار میله‌ای
37
+ bargap=0.15, # فاصله بین میله‌ها
38
+ bargroupgap=0.1 # فاصله بین گروه‌های میله
39
+ )
40
+ return fig
41
+
42
+ # اجرای اپلیکیشن
43
+ if __name__ == '__main__':
44
+ app.run_server(debug=True)