awacke1's picture
Update app.py
bd05b08
raw
history blame
1.22 kB
#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)
st.pydeck_chart(pdk.Deck(
map_style="mapbox://styles/mapbox/dark-v9",
initial_view_state={
"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,
),
],
))