awacke1 commited on
Commit
d6ebfed
·
1 Parent(s): c2fbeee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -53
app.py CHANGED
@@ -1,58 +1,17 @@
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
- "uscities.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
- try:
34
- st.pydeck_chart(pdk.Deck(
35
- map_style="mapbox://styles/mapbox/dark-v9",
36
- initial_view_state={
37
- "lat": df["lat"],
38
- "lng": df["lng"],
39
- #"lat": df["lat"].mean(),
40
- #"lng": df["lng"].mean(),
41
- "zoom": 4,
42
- "pitch": 0,
43
- },
44
- layers=[
45
- pdk.Layer(
46
- "HexagonLayer",
47
- data=df,
48
- get_position=["lng", "lat"],
49
- radius=100,
50
- elevation_scale=4,
51
- elevation_range=[0, 1000],
52
- pickable=True,
53
- extruded=True,
54
- ),
55
- ],
56
- ))
57
- except:
58
- st.write('Error Displaying Map', df["lat"], df["lng"])
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
  import pydeck as pdk
5
 
6
+ def ShowCityDataframe(DATA_URL):
7
+ df = pd.read_csv(DATA_URL)
8
+ st.title("Map Viewer")
9
+ st.text("Search for any city in the United States:")
10
+ search_query = st.text_input(label="City Name", value="")
11
+ if search_query != "":
12
+ df = df[df["city"].str.contains(search_query) == True]
13
+ st.subheader("City Detail")
14
+ st.write(df)
15
+
16
+ Cities = "uscities.csv"
17
+ ShowCityDataframe(Cities)