Spaces:
Runtime error
Runtime error
File size: 1,605 Bytes
d851ab7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 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 برای بهروزرسانی گراف
@app.callback(
Output('main-graph', 'figure'),
[Input('column-dropdown', 'value')]
)
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) |