File size: 1,090 Bytes
38532d2
 
 
 
f6b145c
 
 
38532d2
f6b145c
 
 
 
 
 
 
 
 
 
 
 
38532d2
f6b145c
 
 
 
 
38532d2
f6b145c
 
38532d2
f6b145c
 
 
38532d2
f6b145c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import streamlit as st
import pandas as pd
import pydeck as pdk

def show_pydeck_scatterplot(data_url):
    # create a container for the map and controls
    container = st.container()

    # load the data
    data = pd.read_csv(data_url, usecols=['latitude', 'longitude', 'time'])

    # create the scatter plot layer
    scatter_layer = pdk.Layer(
        'ScatterplotLayer',
        data=data,
        get_position='[longitude, latitude]',
        get_color='[200, 30, time / 100]',
        get_radius=100,
        pickable=True,
    )

    # create the PyDeck view
    view = pdk.ViewState(latitude=data['latitude'].mean(),
                         longitude=data['longitude'].mean(),
                         zoom=10,
                         pitch=50)

    # create the PyDeck map
    map = pdk.Deck(layers=[scatter_layer], initial_view_state=view)

    # add the PyDeck map to the container
    with container:
        st.pydeck_chart(map)

# example usage
data_url = 'https://data.cityofnewyork.us/api/views/7x9x-zpz6/rows.csv?accessType=DOWNLOAD'
show_pydeck_scatterplot(data_url)