Update app.py
Browse files
app.py
CHANGED
|
@@ -46,28 +46,28 @@ with ui.layout_columns(fill=False):
|
|
| 46 |
|
| 47 |
@render.express
|
| 48 |
def total_tippers():
|
| 49 |
-
tips_data()
|
|
|
|
| 50 |
|
| 51 |
with ui.value_box(showcase=ICONS["wallet"]):
|
| 52 |
"Average tip"
|
| 53 |
|
| 54 |
@render.express
|
| 55 |
def average_tip():
|
| 56 |
-
|
| 57 |
-
if
|
| 58 |
-
perc =
|
| 59 |
-
f"{perc.mean():.1%}"
|
| 60 |
|
| 61 |
with ui.value_box(showcase=ICONS["currency-dollar"]):
|
| 62 |
"Average bill"
|
| 63 |
|
| 64 |
@render.express
|
| 65 |
def average_bill():
|
| 66 |
-
|
| 67 |
-
if
|
| 68 |
-
bill =
|
| 69 |
-
f"${bill:.2f}"
|
| 70 |
-
|
| 71 |
|
| 72 |
with ui.layout_columns(col_widths=[6, 6, 12]):
|
| 73 |
with ui.card(full_screen=True):
|
|
@@ -92,8 +92,11 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 92 |
@render_plotly
|
| 93 |
def scatterplot():
|
| 94 |
color = input.scatter_color()
|
|
|
|
|
|
|
|
|
|
| 95 |
return px.scatter(
|
| 96 |
-
|
| 97 |
x="سن",
|
| 98 |
y="id",
|
| 99 |
color=None if color == "none" else color,
|
|
@@ -118,6 +121,9 @@ with ui.layout_columns(col_widths=[6, 6, 12]):
|
|
| 118 |
from ridgeplot import ridgeplot
|
| 119 |
|
| 120 |
dat = tips_data()
|
|
|
|
|
|
|
|
|
|
| 121 |
dat["percent"] = dat.tip / dat.سن
|
| 122 |
yvar = input.tip_perc_y()
|
| 123 |
uvals = dat[yvar].unique()
|
|
@@ -151,10 +157,9 @@ ui.include_css(app_dir / "styles.css")
|
|
| 151 |
@reactive.calc
|
| 152 |
def tips_data():
|
| 153 |
سنی = input.سن()
|
| 154 |
-
idx1 = tips.سن.between(
|
| 155 |
-
idx2 = tips.time.isin(input.time())
|
| 156 |
-
return tips[idx1 & idx2]
|
| 157 |
-
|
| 158 |
|
| 159 |
@reactive.effect
|
| 160 |
@reactive.event(input.reset)
|
|
|
|
| 46 |
|
| 47 |
@render.express
|
| 48 |
def total_tippers():
|
| 49 |
+
data = tips_data()
|
| 50 |
+
return data.shape[0]
|
| 51 |
|
| 52 |
with ui.value_box(showcase=ICONS["wallet"]):
|
| 53 |
"Average tip"
|
| 54 |
|
| 55 |
@render.express
|
| 56 |
def average_tip():
|
| 57 |
+
data = tips_data()
|
| 58 |
+
if data.shape[0] > 0:
|
| 59 |
+
perc = data.tip / data.سن
|
| 60 |
+
return f"{perc.mean():.1%}"
|
| 61 |
|
| 62 |
with ui.value_box(showcase=ICONS["currency-dollar"]):
|
| 63 |
"Average bill"
|
| 64 |
|
| 65 |
@render.express
|
| 66 |
def average_bill():
|
| 67 |
+
data = tips_data()
|
| 68 |
+
if data.shape[0] > 0:
|
| 69 |
+
bill = data.سن.mean()
|
| 70 |
+
return f"${bill:.2f}"
|
|
|
|
| 71 |
|
| 72 |
with ui.layout_columns(col_widths=[6, 6, 12]):
|
| 73 |
with ui.card(full_screen=True):
|
|
|
|
| 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,
|
|
|
|
| 121 |
from ridgeplot import ridgeplot
|
| 122 |
|
| 123 |
dat = tips_data()
|
| 124 |
+
if dat.shape[0] == 0:
|
| 125 |
+
return {} # return empty plot if no data available
|
| 126 |
+
|
| 127 |
dat["percent"] = dat.tip / dat.سن
|
| 128 |
yvar = input.tip_perc_y()
|
| 129 |
uvals = dat[yvar].unique()
|
|
|
|
| 157 |
@reactive.calc
|
| 158 |
def tips_data():
|
| 159 |
سنی = input.سن()
|
| 160 |
+
idx1 = tips.سن.between(سنی[0], سنی[1]) # Corrected range filter
|
| 161 |
+
idx2 = tips.time.isin(input.time()) # Filter based on selected time (Twitter, Instagram)
|
| 162 |
+
return tips[idx1 & idx2] # Apply filters to the tips data
|
|
|
|
| 163 |
|
| 164 |
@reactive.effect
|
| 165 |
@reactive.event(input.reset)
|