meaguirre3 commited on
Commit
a89372c
·
verified ·
1 Parent(s): 0dd3073

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -19,7 +19,15 @@ locations = pd.DataFrame({
19
  app = Dash(__name__)
20
  server = app.server # ← requerido por Hugging Face
21
 
22
- scatter_fig = px.scatter(locations, x="lon", y="lat", hover_name="id", custom_data=["id"])
 
 
 
 
 
 
 
 
23
  scatter_fig.update_layout(dragmode='lasso')
24
 
25
  app.layout = html.Div([
@@ -42,7 +50,12 @@ def actualizar_mapa(selection):
42
  if not selection or "points" not in selection:
43
  return "Selecciona al menos un punto.", ""
44
 
45
- ids = [p['customdata'][0] for p in selection['points']]
 
 
 
 
 
46
  seleccion = locations[locations["id"].isin(ids)]
47
 
48
  fmap = folium.Map(location=[seleccion["lat"].mean(), seleccion["lon"].mean()], zoom_start=10)
 
19
  app = Dash(__name__)
20
  server = app.server # ← requerido por Hugging Face
21
 
22
+ # Asegurar que custom_data esté presente
23
+ scatter_fig = px.scatter(
24
+ locations,
25
+ x="lon",
26
+ y="lat",
27
+ hover_name="id",
28
+ hover_data=["id"],
29
+ custom_data=["id"]
30
+ )
31
  scatter_fig.update_layout(dragmode='lasso')
32
 
33
  app.layout = html.Div([
 
50
  if not selection or "points" not in selection:
51
  return "Selecciona al menos un punto.", ""
52
 
53
+ try:
54
+ ids = [p['customdata'][0] for p in selection['points']]
55
+ except (KeyError, TypeError):
56
+ # Fallback por si no llega customdata
57
+ ids = [int(p['hovertext']) for p in selection['points']]
58
+
59
  seleccion = locations[locations["id"].isin(ids)]
60
 
61
  fmap = folium.Map(location=[seleccion["lat"].mean(), seleccion["lon"].mean()], zoom_start=10)