Update app.py
Browse files
app.py
CHANGED
@@ -1,58 +1,23 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
-
import json
|
3 |
-
import geopandas as gpd
|
4 |
-
import pyproj
|
5 |
-
import plotly.graph_objs as go
|
6 |
-
polygon = gpd.read_file(r"\Downloads\CityBoundaries.shp")
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
#index geojson
|
30 |
-
i=1
|
31 |
-
for feature in j_file["features"]:
|
32 |
-
feature ['id'] = str(i).zfill(2)
|
33 |
-
i += 1
|
34 |
-
|
35 |
-
# mapbox token
|
36 |
-
mapboxt = 'MapBox Token'
|
37 |
-
|
38 |
-
# define layers and plot map
|
39 |
-
choro = go.Choroplethmapbox(z=map_df['STFIPS'], locations = map_df.index, colorscale = 'Viridis', geojson = j_file, text = map_df['NAME'], marker_line_width=0.1)
|
40 |
-
# Your choropleth data here
|
41 |
-
|
42 |
-
|
43 |
-
scatt = go.Scattermapbox(lat=Lat,lon=Long,mode='markers+text',below='False', marker=dict( size=12, color ='rgb(56, 44, 100)'))
|
44 |
-
# Your scatter data here
|
45 |
-
|
46 |
-
layout = go.Layout(title_text ='USA Cities', title_x =0.5, width=950, height=700,mapbox = dict(center= dict(lat=37, lon=-95),accesstoken= mapboxt, zoom=4,style="stamen-terrain"))
|
47 |
-
|
48 |
-
|
49 |
-
# streamlit multiselect widget
|
50 |
-
layer1 = st.multiselect('Layer Selection', [choro, scatt], format_func=lambda x: 'Polygon' if x==choro else 'Points')
|
51 |
-
|
52 |
-
|
53 |
-
#st.write('Layer 1:', layer1)
|
54 |
-
fig = go.Figure(data=layer1, layout=layout)
|
55 |
-
|
56 |
-
|
57 |
-
# display streamlit
|
58 |
-
st.plotly_chart(fig)
|
|
|
1 |
+
import altair as alt
|
2 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
african_countries = alt.topo_feature(
|
5 |
+
"https://raw.githubusercontent.com/deldersveld/topojson/master/continents/africa.json",
|
6 |
+
"continent_Africa_subunits",
|
7 |
+
)
|
8 |
+
africa_chart = (
|
9 |
+
alt.Chart(african_countries)
|
10 |
+
.mark_geoshape(stroke="white", strokeWidth=2)
|
11 |
+
.encode(
|
12 |
+
color="value:Q",
|
13 |
+
tooltip=[
|
14 |
+
alt.Tooltip("properties.geounit:O", title="Country name"),
|
15 |
+
alt.Tooltip("value:Q", title="Indicator value"),
|
16 |
+
],
|
17 |
+
)
|
18 |
+
.transform_lookup(
|
19 |
+
lookup="properties.geounit",
|
20 |
+
from_=alt.LookupData(filtered_data, "Geo Name", ["value"]),
|
21 |
+
)
|
22 |
+
)
|
23 |
+
st.altair_chart(africa_chart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|