Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
write a streamlit map viewer that can show the detail and search for any city in the united states.
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
import pydeck as pdk
|
7 |
+
|
8 |
+
DATA_URL = (
|
9 |
+
"/data/cities.csv"
|
10 |
+
)
|
11 |
+
|
12 |
+
# Load data into dataframe
|
13 |
+
df = pd.read_csv(DATA_URL)
|
14 |
+
|
15 |
+
st.title("Map Viewer")
|
16 |
+
|
17 |
+
# Create a text element and let the reader know the data is loading.
|
18 |
+
st.text("Loading data...")
|
19 |
+
st.text("Search for any city in the United States:")
|
20 |
+
|
21 |
+
# Get the user's search query
|
22 |
+
search_query = st.text_input(label="City Name", value="")
|
23 |
+
|
24 |
+
# Filter the dataframe
|
25 |
+
if search_query != "":
|
26 |
+
df = df[df["City"].str.contains(search_query) == True]
|
27 |
+
|
28 |
+
# Create a subheader
|
29 |
+
st.subheader("City Detail")
|
30 |
+
|
31 |
+
# Show the data
|
32 |
+
st.write(df)
|
33 |
+
|
34 |
+
st.pydeck_chart(pdk.Deck(
|
35 |
+
map_style="mapbox://styles/mapbox/dark-v9",
|
36 |
+
initial_view_state={
|
37 |
+
"latitude": df.Lat.mean(),
|
38 |
+
"longitude": df.Lon.mean(),
|
39 |
+
"zoom": 4,
|
40 |
+
"pitch": 0,
|
41 |
+
},
|
42 |
+
layers=[
|
43 |
+
pdk.Layer(
|
44 |
+
"HexagonLayer",
|
45 |
+
data=df,
|
46 |
+
get_position=["Lon", "Lat"],
|
47 |
+
radius=100,
|
48 |
+
elevation_scale=4,
|
49 |
+
elevation_range=[0, 1000],
|
50 |
+
pickable=True,
|
51 |
+
extruded=True,
|
52 |
+
),
|
53 |
+
],
|
54 |
+
))
|