File size: 1,439 Bytes
cfa798a
639ada3
 
 
 
 
 
 
7cb1949
639ada3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591749c
639ada3
 
 
 
 
 
52f72d6
 
 
 
c2fbeee
 
 
 
52f72d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#write a streamlit map viewer that can show the detail and search for any city in the united states.

import streamlit as st
import pandas as pd
import numpy as np
import pydeck as pdk

DATA_URL = (
"uscities.csv"
)

# Load data into dataframe
df = pd.read_csv(DATA_URL)

st.title("Map Viewer")

# Create a text element and let the reader know the data is loading.
st.text("Loading data...")
st.text("Search for any city in the United States:")

# Get the user's search query
search_query = st.text_input(label="City Name", value="")

# Filter the dataframe
if search_query != "":
    df = df[df["city"].str.contains(search_query) == True]

# Create a subheader
st.subheader("City Detail")

# Show the data
st.write(df)
try:
    st.pydeck_chart(pdk.Deck(
        map_style="mapbox://styles/mapbox/dark-v9",
        initial_view_state={
            "lat": df["lat"],
            "lng": df["lng"],
            #"lat": df["lat"].mean(),
            #"lng": df["lng"].mean(),
            "zoom": 4,
            "pitch": 0,
        },
        layers=[
            pdk.Layer(
                "HexagonLayer",
                data=df,
                get_position=["lng", "lat"],
                radius=100,
                elevation_scale=4,
                elevation_range=[0, 1000],
                pickable=True,
                extruded=True,
            ),
        ],
    ))
except:
    st.write('Error Displaying Map', df["lat"], df["lng"])