Update app.py
Browse files
app.py
CHANGED
|
@@ -60,7 +60,9 @@ with ui.layout_columns(fill=False):
|
|
| 60 |
def average_tip():
|
| 61 |
data = tips_data()
|
| 62 |
if data.shape[0] > 0:
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
with ui.value_box(showcase=ICONS["currency-dollar"]):
|
| 66 |
"میانگین سن"
|
|
@@ -69,22 +71,26 @@ with ui.layout_columns(fill=False):
|
|
| 69 |
def average_bill():
|
| 70 |
data = tips_data()
|
| 71 |
if data.shape[0] > 0:
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# نمودار و جدول
|
| 75 |
with ui.layout_columns(col_widths=[6, 6, 12]):
|
| 76 |
with ui.card(full_screen=True):
|
| 77 |
ui.card_header("جدول دادهها")
|
| 78 |
|
|
|
|
| 79 |
@render.data_frame
|
| 80 |
def table():
|
| 81 |
return tips_data()
|
| 82 |
|
|
|
|
| 83 |
@render_plotly
|
| 84 |
def scatterplot():
|
| 85 |
data = tips_data()
|
| 86 |
if data.shape[0] == 0:
|
| 87 |
-
return {}
|
| 88 |
return px.scatter(
|
| 89 |
data,
|
| 90 |
x="سن",
|
|
@@ -96,8 +102,10 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 96 |
)
|
| 97 |
|
| 98 |
with ui.card(full_screen=True):
|
|
|
|
| 99 |
with ui.card_header(class_="d-flex justify-content-between align-items-center"):
|
| 100 |
"تحلیل پراکندگی احساس"
|
|
|
|
| 101 |
with ui.popover(title="گروهبندی بر اساس متغیر"):
|
| 102 |
ICONS["ellipsis"]
|
| 103 |
ui.input_radio_buttons(
|
|
@@ -108,20 +116,23 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 108 |
inline=True,
|
| 109 |
)
|
| 110 |
|
|
|
|
| 111 |
@render_plotly
|
| 112 |
def tip_perc():
|
| 113 |
from ridgeplot import ridgeplot
|
| 114 |
|
| 115 |
dat = tips_data()
|
| 116 |
if dat.shape[0] == 0:
|
| 117 |
-
return {}
|
| 118 |
|
| 119 |
-
dat["percent"] = dat["tip"] # استفاده از tip به عنوان درصد احساس
|
| 120 |
-
yvar = input.tip_perc_y()
|
| 121 |
-
uvals = dat[yvar].unique()
|
| 122 |
|
|
|
|
| 123 |
samples = [[dat.percent[dat[yvar] == val]] for val in uvals]
|
| 124 |
|
|
|
|
| 125 |
plt = ridgeplot(
|
| 126 |
samples=samples,
|
| 127 |
labels=uvals,
|
|
@@ -130,13 +141,15 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 130 |
colormode="row-index",
|
| 131 |
)
|
| 132 |
|
|
|
|
| 133 |
plt.update_layout(
|
| 134 |
legend=dict(
|
| 135 |
orientation="h", yanchor="bottom", y=1.02, xanchor="center", x=0.5
|
| 136 |
)
|
| 137 |
)
|
| 138 |
|
| 139 |
-
return plt
|
|
|
|
| 140 |
|
| 141 |
# اعمال CSS
|
| 142 |
ui.include_css(app_dir / "styles.css")
|
|
|
|
| 60 |
def average_tip():
|
| 61 |
data = tips_data()
|
| 62 |
if data.shape[0] > 0:
|
| 63 |
+
ui.h3(f"میانگین انعام: {data['tip'].mean():.2f}")
|
| 64 |
+
else:
|
| 65 |
+
ui.h3("دادهای برای محاسبه میانگین وجود ندارد.")
|
| 66 |
|
| 67 |
with ui.value_box(showcase=ICONS["currency-dollar"]):
|
| 68 |
"میانگین سن"
|
|
|
|
| 71 |
def average_bill():
|
| 72 |
data = tips_data()
|
| 73 |
if data.shape[0] > 0:
|
| 74 |
+
ui.h3(f"میانگین سن: {data['سن'].mean():.1f} سال")
|
| 75 |
+
else:
|
| 76 |
+
ui.h3("دادهای برای محاسبه میانگین سن وجود ندارد.")
|
| 77 |
|
| 78 |
# نمودار و جدول
|
| 79 |
with ui.layout_columns(col_widths=[6, 6, 12]):
|
| 80 |
with ui.card(full_screen=True):
|
| 81 |
ui.card_header("جدول دادهها")
|
| 82 |
|
| 83 |
+
# رندر کردن دادهها در قالب جدول
|
| 84 |
@render.data_frame
|
| 85 |
def table():
|
| 86 |
return tips_data()
|
| 87 |
|
| 88 |
+
# رندر کردن نمودار پراکندگی
|
| 89 |
@render_plotly
|
| 90 |
def scatterplot():
|
| 91 |
data = tips_data()
|
| 92 |
if data.shape[0] == 0:
|
| 93 |
+
return {} # بازگرداندن دادههای خالی در صورت عدم وجود داده
|
| 94 |
return px.scatter(
|
| 95 |
data,
|
| 96 |
x="سن",
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
with ui.card(full_screen=True):
|
| 105 |
+
# عنوان برای تحلیل پراکندگی احساس
|
| 106 |
with ui.card_header(class_="d-flex justify-content-between align-items-center"):
|
| 107 |
"تحلیل پراکندگی احساس"
|
| 108 |
+
# ایجاد یک Popover برای انتخاب متغیر گروهبندی
|
| 109 |
with ui.popover(title="گروهبندی بر اساس متغیر"):
|
| 110 |
ICONS["ellipsis"]
|
| 111 |
ui.input_radio_buttons(
|
|
|
|
| 116 |
inline=True,
|
| 117 |
)
|
| 118 |
|
| 119 |
+
# رندر کردن نمودار ridgeplot
|
| 120 |
@render_plotly
|
| 121 |
def tip_perc():
|
| 122 |
from ridgeplot import ridgeplot
|
| 123 |
|
| 124 |
dat = tips_data()
|
| 125 |
if dat.shape[0] == 0:
|
| 126 |
+
return {} # بازگرداندن دادههای خالی در صورت عدم وجود داده
|
| 127 |
|
| 128 |
+
dat["percent"] = dat["tip"] # استفاده از 'tip' به عنوان درصد احساس
|
| 129 |
+
yvar = input.tip_perc_y() # دریافت انتخاب از کاربر
|
| 130 |
+
uvals = dat[yvar].unique() # استخراج مقادیر یکتای متغیر انتخابی
|
| 131 |
|
| 132 |
+
# ایجاد نمونهها برای رسم نمودار ridgeplot
|
| 133 |
samples = [[dat.percent[dat[yvar] == val]] for val in uvals]
|
| 134 |
|
| 135 |
+
# ایجاد نمودار ridgeplot
|
| 136 |
plt = ridgeplot(
|
| 137 |
samples=samples,
|
| 138 |
labels=uvals,
|
|
|
|
| 141 |
colormode="row-index",
|
| 142 |
)
|
| 143 |
|
| 144 |
+
# تنظیمات نهایی برای نمودار
|
| 145 |
plt.update_layout(
|
| 146 |
legend=dict(
|
| 147 |
orientation="h", yanchor="bottom", y=1.02, xanchor="center", x=0.5
|
| 148 |
)
|
| 149 |
)
|
| 150 |
|
| 151 |
+
return plt # بازگشت نمودار
|
| 152 |
+
|
| 153 |
|
| 154 |
# اعمال CSS
|
| 155 |
ui.include_css(app_dir / "styles.css")
|