awacke1 commited on
Commit
f6b145c
·
1 Parent(s): 38532d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -24
app.py CHANGED
@@ -2,32 +2,36 @@ import streamlit as st
2
  import pandas as pd
3
  import pydeck as pdk
4
 
5
- # create a container for the map and controls
6
- container = st.container()
 
7
 
8
- # load the data
9
- data_url = 'https://data.cityofnewyork.us/api/views/7x9x-zpz6/rows.csv?accessType=DOWNLOAD'
10
- data = pd.read_csv(data_url, usecols=['latitude', 'longitude', 'time'])
 
 
 
 
 
 
 
 
 
11
 
12
- # create the scatter plot layer
13
- scatter_layer = pdk.Layer(
14
- 'ScatterplotLayer',
15
- data=data,
16
- get_position='[longitude, latitude]',
17
- get_color='[200, 30, time / 100]',
18
- get_radius=100,
19
- pickable=True,
20
- )
21
 
22
- # create the PyDeck view
23
- view = pdk.ViewState(latitude=data['latitude'].mean(),
24
- longitude=data['longitude'].mean(),
25
- zoom=10,
26
- pitch=50)
27
 
28
- # create the PyDeck map
29
- map = pdk.Deck(layers=[scatter_layer], initial_view_state=view)
 
30
 
31
- # add the PyDeck map to the container
32
- with container:
33
- st.pydeck_chart(map)
 
2
  import pandas as pd
3
  import pydeck as pdk
4
 
5
+ def show_pydeck_scatterplot(data_url):
6
+ # create a container for the map and controls
7
+ container = st.container()
8
 
9
+ # load the data
10
+ data = pd.read_csv(data_url, usecols=['latitude', 'longitude', 'time'])
11
+
12
+ # create the scatter plot layer
13
+ scatter_layer = pdk.Layer(
14
+ 'ScatterplotLayer',
15
+ data=data,
16
+ get_position='[longitude, latitude]',
17
+ get_color='[200, 30, time / 100]',
18
+ get_radius=100,
19
+ pickable=True,
20
+ )
21
 
22
+ # create the PyDeck view
23
+ view = pdk.ViewState(latitude=data['latitude'].mean(),
24
+ longitude=data['longitude'].mean(),
25
+ zoom=10,
26
+ pitch=50)
 
 
 
 
27
 
28
+ # create the PyDeck map
29
+ map = pdk.Deck(layers=[scatter_layer], initial_view_state=view)
 
 
 
30
 
31
+ # add the PyDeck map to the container
32
+ with container:
33
+ st.pydeck_chart(map)
34
 
35
+ # example usage
36
+ data_url = 'https://data.cityofnewyork.us/api/views/7x9x-zpz6/rows.csv?accessType=DOWNLOAD'
37
+ show_pydeck_scatterplot(data_url)