Update app.py
Browse files
app.py
CHANGED
|
@@ -74,35 +74,21 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 74 |
ui.card_header("Tips data")
|
| 75 |
|
| 76 |
@render.data_frame
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
@render_plotly
|
| 93 |
-
def scatterplot():
|
| 94 |
-
color = input.scatter_color()
|
| 95 |
-
data = tips_data()
|
| 96 |
-
if data.shape[0] == 0:
|
| 97 |
-
return {} # return empty plot if no data available
|
| 98 |
-
return px.scatter(
|
| 99 |
-
data,
|
| 100 |
-
x="سن",
|
| 101 |
-
y="id",
|
| 102 |
-
color=None if color == "none" else color,
|
| 103 |
-
trendline="lowess",
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
with ui.card(full_screen=True):
|
| 107 |
with ui.card_header(class_="d-flex justify-content-between align-items-center"):
|
| 108 |
"Tip percentages"
|
|
@@ -156,10 +142,12 @@ ui.include_css(app_dir / "styles.css")
|
|
| 156 |
|
| 157 |
@reactive.calc
|
| 158 |
def tips_data():
|
| 159 |
-
سنی = input.سن()
|
| 160 |
-
idx1 = tips
|
| 161 |
-
idx2 = tips
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
|
| 164 |
@reactive.effect
|
| 165 |
@reactive.event(input.reset)
|
|
|
|
| 74 |
ui.card_header("Tips data")
|
| 75 |
|
| 76 |
@render.data_frame
|
| 77 |
+
def table():
|
| 78 |
+
return tips_data() # جدول با دادههای فیلتر شده
|
| 79 |
+
|
| 80 |
+
@render_plotly
|
| 81 |
+
def scatterplot():
|
| 82 |
+
data = tips_data() # دادههای فیلتر شده برای نمودار
|
| 83 |
+
if data.shape[0] == 0:
|
| 84 |
+
return {} # اگر هیچ دادهای نیست، نمودار خالی برگردانده میشود
|
| 85 |
+
return px.scatter(
|
| 86 |
+
data,
|
| 87 |
+
x="سن", # استفاده از ستون "سن"
|
| 88 |
+
y="id", # استفاده از ستون "id"
|
| 89 |
+
color=None if input.scatter_color() == "none" else input.scatter_color(), # رنگ بر اساس انتخاب
|
| 90 |
+
trendline="lowess", # اضافه کردن trendline به نمودار
|
| 91 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
with ui.card(full_screen=True):
|
| 93 |
with ui.card_header(class_="d-flex justify-content-between align-items-center"):
|
| 94 |
"Tip percentages"
|
|
|
|
| 142 |
|
| 143 |
@reactive.calc
|
| 144 |
def tips_data():
|
| 145 |
+
سنی = input.سن() # رنج سنی
|
| 146 |
+
idx1 = tips["سن"].between(سنی[0], سنی[1]) # فیلتر کردن بر اساس سن
|
| 147 |
+
idx2 = tips["تاریخ"].isin(input.time()) # فیلتر کردن بر اساس تاریخ (خدمات)
|
| 148 |
+
filtered_data = tips[idx1 & idx2] # دادههای فیلتر شده
|
| 149 |
+
print(filtered_data) # برای دیباگ کردن و اطمینان از فیلتر درست
|
| 150 |
+
return filtered_dat
|
| 151 |
|
| 152 |
@reactive.effect
|
| 153 |
@reactive.event(input.reset)
|