Spaces:
Runtime error
Runtime error
| import pandas as pd | |
| import plotly.express as px | |
| from dash import Dash, dcc, html, Input, Output | |
| # بارگیری داده از فایل CSV | |
| df = pd.read_csv('/content/گروهبندی مزارع کراپ لاگ 1403.csv') # فایل CSV خود را وارد کنید | |
| # ایجاد اپلیکیشن Dash | |
| app = Dash(__name__) | |
| # تعریف لیست گزینهها برای انتخاب نام ستون | |
| column_options = [{'label': col, 'value': col} for col in df.columns] | |
| # طراحی لایههای اپلیکیشن | |
| app.layout = html.Div([ | |
| html.H1('Zali Ai - اداره زراعت و کنترل محصول'), | |
| dcc.Dropdown( | |
| id='column-dropdown', | |
| options=column_options, | |
| value=df.columns[0] # مقدار پیشفرض برای انتخاب ستون | |
| ), | |
| dcc.Graph(id='main-graph') | |
| ]) | |
| # تعریف callback برای بهروزرسانی گراف | |
| def update_graph(selected_column): | |
| fig = px.bar(df, x=selected_column) | |
| fig.update_layout( | |
| title=f'توزیع {selected_column}', # عنوان گراف | |
| xaxis_title=selected_column, # نام محور افقی | |
| yaxis_title='تعداد ردیفها', # نام محور عمودی | |
| barmode='group', # نوع نمودار میلهای | |
| bargap=0.15, # فاصله بین میلهها | |
| bargroupgap=0.1 # فاصله بین گروههای میله | |
| ) | |
| return fig | |
| # اجرای اپلیکیشن | |
| if __name__ == '__main__': | |
| app.run_server(debug=True) |