Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import pandas as pd
|
3 |
import streamlit as st
|
4 |
import matplotlib.pyplot as plt
|
|
|
5 |
|
6 |
# Create a dictionary of states with their region, population, and area
|
7 |
states = {
|
@@ -104,4 +105,42 @@ for region, data in regions.items():
|
|
104 |
|
105 |
# Use Streamlit to display dataframes
|
106 |
for df in dataframes:
|
107 |
-
st.write(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import streamlit as st
|
4 |
import matplotlib.pyplot as plt
|
5 |
+
import pydeck as pdk
|
6 |
|
7 |
# Create a dictionary of states with their region, population, and area
|
8 |
states = {
|
|
|
105 |
|
106 |
# Use Streamlit to display dataframes
|
107 |
for df in dataframes:
|
108 |
+
st.write(df)
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
# Add lat and lon to your states data
|
114 |
+
states = {
|
115 |
+
'Alabama': {'region': 'South', 'population': 4903185, 'area': 135767, 'lat': 32.806671, 'lon': -86.791130},
|
116 |
+
'Alaska': {'region': 'West', 'population': 731545, 'area': 1723337, 'lat': 61.370716, 'lon': -152.404419},
|
117 |
+
# Continue for all states...
|
118 |
+
}
|
119 |
+
|
120 |
+
# Create dataframe from states data
|
121 |
+
df = pd.DataFrame.from_dict(states, orient='index').reset_index()
|
122 |
+
df.columns = ['State', 'Region', 'Population', 'Area', 'Latitude', 'Longitude']
|
123 |
+
|
124 |
+
# Define initial viewport for the deckgl map
|
125 |
+
view_state = pdk.ViewState(
|
126 |
+
longitude=-97.6,
|
127 |
+
latitude=38.5,
|
128 |
+
zoom=3,
|
129 |
+
pitch=50,
|
130 |
+
)
|
131 |
+
|
132 |
+
# Define deckgl layer
|
133 |
+
layer = pdk.Layer(
|
134 |
+
"ScatterplotLayer",
|
135 |
+
data=df,
|
136 |
+
get_position='[Longitude, Latitude]',
|
137 |
+
get_radius='Population',
|
138 |
+
get_fill_color='[200, 30, 0, 160]',
|
139 |
+
pickable=True,
|
140 |
+
auto_highlight=True,
|
141 |
+
)
|
142 |
+
|
143 |
+
# Render the deckgl map in the Streamlit app
|
144 |
+
st.pydeck_chart(pdk.Deck(layers=[layer], initial_view_state=view_state))
|
145 |
+
|
146 |
+
|