Spaces:
Running
Running
try to fix things (failed)
Browse files- polars/05_reactive_plots.py +12 -7
polars/05_reactive_plots.py
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
|
12 |
import marimo
|
13 |
|
14 |
-
__generated_with = "0.11.
|
15 |
app = marimo.App(width="medium")
|
16 |
|
17 |
|
@@ -90,12 +90,11 @@ def _(df, pl):
|
|
90 |
|
91 |
|
92 |
@app.cell
|
93 |
-
def _(df, mo,
|
94 |
# Let's visualize it and get a feel for which region makes sense to focus on for our analysis
|
95 |
duration_counts = df.group_by("duration_seconds").len("count")
|
96 |
fig = px.bar(duration_counts, x="duration_seconds", y="count")
|
97 |
fig.update_layout(selectdirection="h")
|
98 |
-
fig.add_selection(x0=120, y0=0, x1=360, y1=duration_counts.select(pl.col("count").max()).item())
|
99 |
plot = mo.ui.plotly(fig)
|
100 |
plot
|
101 |
return duration_counts, fig, plot
|
@@ -124,10 +123,14 @@ def _(pl, plot):
|
|
124 |
|
125 |
@app.cell
|
126 |
def _(df, pl, plot):
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
131 |
|
132 |
# Calculate how many we are keeping vs throwing away with the filter
|
133 |
duration_in_range = pl.col("duration_seconds").is_between(min_dur, max_dur)
|
@@ -306,6 +309,7 @@ def _(
|
|
306 |
color=color.value,
|
307 |
opacity=alpha.value,
|
308 |
trendline="lowess" if include_trendline.value else None,
|
|
|
309 |
)
|
310 |
chart2 = mo.ui.plotly(fig2)
|
311 |
chart2
|
@@ -329,6 +333,7 @@ def _(chart2, filtered_duration, mo, pl):
|
|
329 |
# Let's look at which sort of songs were included in that region
|
330 |
if len(chart2.value) == 0:
|
331 |
out = mo.md("No data found in selection")
|
|
|
332 |
else:
|
333 |
active_columns = list(chart2.value[0].keys())
|
334 |
column_order = ["track_name", *active_columns, "album_name", "artists"]
|
|
|
11 |
|
12 |
import marimo
|
13 |
|
14 |
+
__generated_with = "0.11.14"
|
15 |
app = marimo.App(width="medium")
|
16 |
|
17 |
|
|
|
90 |
|
91 |
|
92 |
@app.cell
|
93 |
+
def _(df, mo, px):
|
94 |
# Let's visualize it and get a feel for which region makes sense to focus on for our analysis
|
95 |
duration_counts = df.group_by("duration_seconds").len("count")
|
96 |
fig = px.bar(duration_counts, x="duration_seconds", y="count")
|
97 |
fig.update_layout(selectdirection="h")
|
|
|
98 |
plot = mo.ui.plotly(fig)
|
99 |
plot
|
100 |
return duration_counts, fig, plot
|
|
|
123 |
|
124 |
@app.cell
|
125 |
def _(df, pl, plot):
|
126 |
+
if plot.value:
|
127 |
+
min_dur, max_dur = (
|
128 |
+
min(row["duration_seconds"] for row in plot.value),
|
129 |
+
max(row["duration_seconds"] for row in plot.value),
|
130 |
+
)
|
131 |
+
else:
|
132 |
+
print("Could not find a selected region. Using default values instead, try clicking and dragging in the above plot to change them.")
|
133 |
+
min_dur, max_dur = 120, 360
|
134 |
|
135 |
# Calculate how many we are keeping vs throwing away with the filter
|
136 |
duration_in_range = pl.col("duration_seconds").is_between(min_dur, max_dur)
|
|
|
309 |
color=color.value,
|
310 |
opacity=alpha.value,
|
311 |
trendline="lowess" if include_trendline.value else None,
|
312 |
+
render_mode="webgl",
|
313 |
)
|
314 |
chart2 = mo.ui.plotly(fig2)
|
315 |
chart2
|
|
|
333 |
# Let's look at which sort of songs were included in that region
|
334 |
if len(chart2.value) == 0:
|
335 |
out = mo.md("No data found in selection")
|
336 |
+
active_columns = column_order = None
|
337 |
else:
|
338 |
active_columns = list(chart2.value[0].keys())
|
339 |
column_order = ["track_name", *active_columns, "album_name", "artists"]
|