Spaces:
Running
Running
Yao-Ting Yao
commited on
Commit
·
e4fde96
1
Parent(s):
e551f80
Add the date label under thumbnail at streamlit_app.py
Browse files- src/streamlit_app.py +33 -8
src/streamlit_app.py
CHANGED
|
@@ -244,6 +244,9 @@ color_dict_label = {
|
|
| 244 |
chips_df["thumbs"] = chips_df["urls"].apply(
|
| 245 |
lambda urls: [create_thumbnail(p) for p in urls]
|
| 246 |
)
|
|
|
|
|
|
|
|
|
|
| 247 |
# build a list of points dictionary
|
| 248 |
points = (
|
| 249 |
chips_df
|
|
@@ -251,7 +254,7 @@ points = (
|
|
| 251 |
"cls_dim1": "x",
|
| 252 |
"cls_dim2": "y",
|
| 253 |
"Land Cover": "category"
|
| 254 |
-
})[["x","y","category","thumbs"]]
|
| 255 |
.assign(color=chips_df["Land Cover"].map(color_dict_label))
|
| 256 |
.to_dict(orient="records")
|
| 257 |
)
|
|
@@ -334,17 +337,40 @@ plot_html = f"""
|
|
| 334 |
// click event
|
| 335 |
Plotly.newPlot(gd, traces, layout, {{ responsive: true }}).then(() => {{
|
| 336 |
gd.on('plotly_click', evt => {{
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
const container = document.getElementById('image-container');
|
| 340 |
-
// clear out old thumbs
|
| 341 |
container.innerHTML = '';
|
| 342 |
-
|
| 343 |
-
|
|
|
|
| 344 |
if (url) {{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
const img = document.createElement('img');
|
| 346 |
img.src = url;
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
}}
|
| 349 |
}});
|
| 350 |
}});
|
|
@@ -356,7 +382,6 @@ plot_html = f"""
|
|
| 356 |
year = datetime.datetime.now().year
|
| 357 |
footer_html = f"""
|
| 358 |
<style>
|
| 359 |
-
/* make the footer text a bit smaller and centered */
|
| 360 |
#footer {{
|
| 361 |
margin-top: 1rem;
|
| 362 |
color: rgb(204,156,172);
|
|
|
|
| 244 |
chips_df["thumbs"] = chips_df["urls"].apply(
|
| 245 |
lambda urls: [create_thumbnail(p) for p in urls]
|
| 246 |
)
|
| 247 |
+
# create dates Python list
|
| 248 |
+
chips_df["dates_list"] = chips_df["dates"].apply(ast.literal_eval)
|
| 249 |
+
|
| 250 |
# build a list of points dictionary
|
| 251 |
points = (
|
| 252 |
chips_df
|
|
|
|
| 254 |
"cls_dim1": "x",
|
| 255 |
"cls_dim2": "y",
|
| 256 |
"Land Cover": "category"
|
| 257 |
+
})[["x","y","category","thumbs","dates_list"]]
|
| 258 |
.assign(color=chips_df["Land Cover"].map(color_dict_label))
|
| 259 |
.to_dict(orient="records")
|
| 260 |
)
|
|
|
|
| 337 |
// click event
|
| 338 |
Plotly.newPlot(gd, traces, layout, {{ responsive: true }}).then(() => {{
|
| 339 |
gd.on('plotly_click', evt => {{
|
| 340 |
+
// grab thumbs and dates through point index
|
| 341 |
+
const idx = evt.points[0].pointIndex;
|
| 342 |
+
const thumbs = points[idx].thumbs;
|
| 343 |
+
const dates = points[idx].dates_list;
|
| 344 |
+
|
| 345 |
+
// grab image container and clear out old thumbs
|
| 346 |
const container = document.getElementById('image-container');
|
|
|
|
| 347 |
container.innerHTML = '';
|
| 348 |
+
|
| 349 |
+
// append each thumbnail and date
|
| 350 |
+
thumbs.forEach((url, i) => {{
|
| 351 |
if (url) {{
|
| 352 |
+
// create card to bundle image and label content
|
| 353 |
+
const card = document.createElement('div');
|
| 354 |
+
card.style.textAlign = 'center';
|
| 355 |
+
card.style.marginBottom = '8px';
|
| 356 |
+
|
| 357 |
+
//image
|
| 358 |
const img = document.createElement('img');
|
| 359 |
img.src = url;
|
| 360 |
+
img.style.width = '100%';
|
| 361 |
+
img.style.maxHeight = '180px';
|
| 362 |
+
|
| 363 |
+
//label
|
| 364 |
+
const label = document.createElement('p');
|
| 365 |
+
label.textContent = dates[i];
|
| 366 |
+
label.style.color = 'white';
|
| 367 |
+
label.style.margin = '4px 0 0 0';
|
| 368 |
+
label.style.fontSize = '0.9em';
|
| 369 |
+
|
| 370 |
+
//append
|
| 371 |
+
card.appendChild(img);
|
| 372 |
+
card.appendChild(label);
|
| 373 |
+
container.appendChild(card);
|
| 374 |
}}
|
| 375 |
}});
|
| 376 |
}});
|
|
|
|
| 382 |
year = datetime.datetime.now().year
|
| 383 |
footer_html = f"""
|
| 384 |
<style>
|
|
|
|
| 385 |
#footer {{
|
| 386 |
margin-top: 1rem;
|
| 387 |
color: rgb(204,156,172);
|