Josephina commited on
Commit
d923ce9
·
1 Parent(s): 2eba934

update to pydeck

Browse files
Files changed (2) hide show
  1. app.py +63 -39
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import json
2
  import os
3
  from collections import Counter
4
-
5
  import pandas as pd
6
  import plotly.express as px
7
  import plotly.graph_objects as go
@@ -12,8 +12,6 @@ from sentence_transformers import SentenceTransformer
12
 
13
  from semantic_search import predict
14
 
15
- pio.renderers.default = "json"
16
-
17
  HF_TOKEN = os.environ.get("HF_TOKEN")
18
  CITIES_ENRICHED = os.path.join("data", "cities_enriched_manually.csv")
19
  DATA = os.path.join("2025-06-13_musterdatenkatalog.json")
@@ -191,43 +189,69 @@ def load_data() -> pd.DataFrame:
191
  germany = load_data()
192
  germany["lat"] = pd.to_numeric(germany["lat"])
193
  germany["lon"] = pd.to_numeric(germany["lon"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
-
196
- fig_map = px.scatter_mapbox(
197
- germany,
198
- lat="lat",
199
- lon="lon",
200
- hover_name="ORG",
201
- custom_data=["Count"],
202
- # scope="europe",
203
- height=700,
204
  zoom=5,
 
205
  )
206
- # Custom hover template
207
- fig_map.update_traces(
208
- hovertemplate="<br>".join(
209
- [
210
- "Kommune: %{hovertext}", # Use hover_name as hovertext
211
- "Count: %{customdata[0]}", # Access elements in custom_data
212
- ]
213
- )
214
- )
215
- fig_map.update_layout(
216
- # geo=dict(
217
- # showland=True,
218
- # landcolor="LightGray",
219
- # showocean=True,
220
- # oceancolor="LightBlue",
221
- # # showcountries=True,
222
- # # countrycolor="Gray",
223
- # showsubunits=True,
224
- # # subunitcolor="Gray",
225
- # fitbounds="locations", # Fit the map bounds to the locations
226
- # lataxis=dict(range=[47, 55]), # Approximate latitude range for Germany
227
- # lonaxis=dict(range=[5, 16]), # Approximate longitude range for Germany
228
- # ),
229
- mapbox_style="carto-positron",
230
- # height=700,
231
  )
232
 
233
  st.title("Musterdatenkatalog (MDK)")
@@ -389,5 +413,5 @@ st.markdown(
389
  """,
390
  unsafe_allow_html=True,
391
  )
392
- st.write(pio.renderers)
393
- st.plotly_chart(fig_map)
 
1
  import json
2
  import os
3
  from collections import Counter
4
+ import pydeck as pdk
5
  import pandas as pd
6
  import plotly.express as px
7
  import plotly.graph_objects as go
 
12
 
13
  from semantic_search import predict
14
 
 
 
15
  HF_TOKEN = os.environ.get("HF_TOKEN")
16
  CITIES_ENRICHED = os.path.join("data", "cities_enriched_manually.csv")
17
  DATA = os.path.join("2025-06-13_musterdatenkatalog.json")
 
189
  germany = load_data()
190
  germany["lat"] = pd.to_numeric(germany["lat"])
191
  germany["lon"] = pd.to_numeric(germany["lon"])
192
+ germany = germany[["ORG", "lat", "lon", "Count"]]
193
+
194
+
195
+ # fig_map = px.scatter_mapbox(
196
+ # germany,
197
+ # lat="lat",
198
+ # lon="lon",
199
+ # hover_name="ORG",
200
+ # custom_data=["Count"],
201
+ # # scope="europe",
202
+ # height=700,
203
+ # zoom=5,
204
+ # )
205
+ # # Custom hover template
206
+ # fig_map.update_traces(
207
+ # hovertemplate="<br>".join(
208
+ # [
209
+ # "Kommune: %{hovertext}", # Use hover_name as hovertext
210
+ # "Count: %{customdata[0]}", # Access elements in custom_data
211
+ # ]
212
+ # )
213
+ # )
214
+ # fig_map.update_layout(
215
+ # # geo=dict(
216
+ # # showland=True,
217
+ # # landcolor="LightGray",
218
+ # # showocean=True,
219
+ # # oceancolor="LightBlue",
220
+ # # # showcountries=True,
221
+ # # # countrycolor="Gray",
222
+ # # showsubunits=True,
223
+ # # # subunitcolor="Gray",
224
+ # # fitbounds="locations", # Fit the map bounds to the locations
225
+ # # lataxis=dict(range=[47, 55]), # Approximate latitude range for Germany
226
+ # # lonaxis=dict(range=[5, 16]), # Approximate longitude range for Germany
227
+ # # ),
228
+ # mapbox_style="carto-positron",
229
+ # # height=700,
230
+ # )
231
+
232
+ # Define the layer
233
+ layer = pdk.Layer(
234
+ "ScatterplotLayer",
235
+ data=germany,
236
+ get_position="[lon, lat]",
237
+ get_radius=10000, # or use 'Count' to scale
238
+ get_color=[255, 0, 0, 160],
239
+ pickable=True,
240
+ )
241
 
242
+ # Define the view
243
+ view_state = pdk.ViewState(
244
+ latitude=51.1657,
245
+ longitude=10.4515,
 
 
 
 
 
246
  zoom=5,
247
+ pitch=0,
248
  )
249
+
250
+ # Render the deck
251
+ r = pdk.Deck(
252
+ layers=[layer],
253
+ initial_view_state=view_state,
254
+ tooltip={"text": "Kommune: {ORG}\nCount: {Count}"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  )
256
 
257
  st.title("Musterdatenkatalog (MDK)")
 
413
  """,
414
  unsafe_allow_html=True,
415
  )
416
+ # st.plotly_chart(fig_map)
417
+ st.pydeck_chart(r, use_container_width=True)
requirements.txt CHANGED
@@ -2,4 +2,5 @@ plotly-express>=0.4.1
2
  plotly>=5.14.1
3
  altair<5
4
  sentence-transformers
5
- safetensors
 
 
2
  plotly>=5.14.1
3
  altair<5
4
  sentence-transformers
5
+ safetensors
6
+ pydeck