Spaces:
Sleeping
Sleeping
kunifujiwara
commited on
Commit
•
611d9b7
1
Parent(s):
3ec7a4c
modify pages
Browse files
Home.py
CHANGED
@@ -17,13 +17,21 @@ import numpy as np
|
|
17 |
st.set_page_config(layout="wide")
|
18 |
|
19 |
# Data source
|
20 |
-
|
21 |
-
"
|
22 |
-
"
|
23 |
-
"千葉県": "
|
24 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
|
|
|
|
|
27 |
@st.cache_data
|
28 |
def get_geom_data(prefecture):
|
29 |
response = requests.get(data_links[prefecture])
|
@@ -35,9 +43,6 @@ def get_geom_data(prefecture):
|
|
35 |
st.error(f"Failed to fetch data for {prefecture}. Status code: {response.status_code}")
|
36 |
return None
|
37 |
|
38 |
-
def get_data_columns(gdf):
|
39 |
-
return gdf.select_dtypes(include=[float, int]).columns.tolist()
|
40 |
-
|
41 |
def create_discontinuous_colormap(n_colors):
|
42 |
cmap = plt.get_cmap('Greens')
|
43 |
colors = [cmap(i / (n_colors - 1)) for i in range(n_colors)]
|
@@ -69,7 +74,7 @@ def calculate_zoom_level(bbox):
|
|
69 |
def app():
|
70 |
st.title("日本全国緑被率マップ (町丁目別)")
|
71 |
|
72 |
-
prefecture = st.selectbox("都道府県",
|
73 |
|
74 |
gdf = get_geom_data(prefecture)
|
75 |
|
@@ -87,8 +92,7 @@ def app():
|
|
87 |
else:
|
88 |
gdf_filtered = gdf
|
89 |
|
90 |
-
|
91 |
-
selected_attribute = st.selectbox("指標", attributes)
|
92 |
|
93 |
# Custom CSS to create a box around the color scale controls
|
94 |
st.markdown("""
|
@@ -104,16 +108,16 @@ def app():
|
|
104 |
|
105 |
# Color scale controls in an expander
|
106 |
with st.expander("カラースケール設定", expanded=True):
|
107 |
-
|
108 |
col1, col2, col3, col4 = st.columns(4)
|
109 |
with col1:
|
110 |
-
n_colors = st.slider("分割数", min_value=2, max_value=20, value=
|
111 |
with col2:
|
112 |
alpha = st.slider("透過率", min_value=0.0, max_value=1.0, value=0.8, step=0.1)
|
113 |
with col3:
|
114 |
-
vmin = st.number_input("最小値", value=
|
115 |
with col4:
|
116 |
-
vmax = st.number_input("最大値", value=
|
117 |
st.markdown('</div>', unsafe_allow_html=True)
|
118 |
|
119 |
# Other controls
|
@@ -169,7 +173,7 @@ def app():
|
|
169 |
layers=[layer],
|
170 |
initial_view_state=view_state,
|
171 |
map_style="mapbox://styles/mapbox/light-v9",
|
172 |
-
tooltip={"text": "{CITY_NAME_x}\n{" + selected_attribute + "}"}
|
173 |
)
|
174 |
|
175 |
st.pydeck_chart(r)
|
@@ -185,8 +189,8 @@ def app():
|
|
185 |
st.image(f"data:image/png;base64,{legend_img}", caption="Color Scale", use_column_width=True)
|
186 |
|
187 |
if st.checkbox("Show raw data"):
|
188 |
-
st.write(gdf_filtered[['CITY_NAME_x', selected_attribute]])
|
189 |
-
|
190 |
st.markdown(
|
191 |
"""
|
192 |
**データソース**
|
|
|
17 |
st.set_page_config(layout="wide")
|
18 |
|
19 |
# Data source
|
20 |
+
prefectures = {
|
21 |
+
"北海道": "Hokkaido", "青森県": "Aomori", "岩手県": "Iwate", "宮城県": "Miyagi", "秋田県": "Akita",
|
22 |
+
"山形県": "Yamagata", "福島県": "Fukushima", "茨城県": "Ibaraki", "栃木県": "Tochigi", "群馬県": "Gunma",
|
23 |
+
"埼玉県": "Saitama", "千葉県": "Chiba", "東京都": "Tokyo", "神奈川県": "Kanagawa", "新潟県": "Niigata",
|
24 |
+
"富山県": "Toyama", "石川県": "Ishikawa", "福井県": "Fukui", "山梨県": "Yamanashi", "長野県": "Nagano",
|
25 |
+
"岐阜県": "Gifu", "静岡県": "Shizuoka", "愛知県": "Aichi", "三重県": "Mie", "滋賀県": "Shiga",
|
26 |
+
"京都府": "Kyoto", "大阪府": "Osaka", "兵庫県": "Hyogo", "奈良県": "Nara", "和歌山県": "Wakayama",
|
27 |
+
"鳥取県": "Tottori", "島根県": "Shimane", "岡山県": "Okayama", "広島県": "Hiroshima", "山口県": "Yamaguchi",
|
28 |
+
"徳島県": "Tokushima", "香川県": "Kagawa", "愛媛県": "Ehime", "高知県": "Kochi", "福岡県": "Fukuoka",
|
29 |
+
"佐賀県": "Saga", "長崎県": "Nagasaki", "熊本県": "Kumamoto", "大分県": "Oita", "宮崎県": "Miyazaki",
|
30 |
+
"鹿児島県": "Kagoshima", "沖縄県": "Okinawa"
|
31 |
}
|
32 |
|
33 |
+
data_links = {pref_jp: f"https://raw.githubusercontent.com/kunifujiwara/data/master/frac_veg/FRAC_VEG_{pref_en}.geojson" for pref_jp, pref_en in prefectures.items()}
|
34 |
+
|
35 |
@st.cache_data
|
36 |
def get_geom_data(prefecture):
|
37 |
response = requests.get(data_links[prefecture])
|
|
|
43 |
st.error(f"Failed to fetch data for {prefecture}. Status code: {response.status_code}")
|
44 |
return None
|
45 |
|
|
|
|
|
|
|
46 |
def create_discontinuous_colormap(n_colors):
|
47 |
cmap = plt.get_cmap('Greens')
|
48 |
colors = [cmap(i / (n_colors - 1)) for i in range(n_colors)]
|
|
|
74 |
def app():
|
75 |
st.title("日本全国緑被率マップ (町丁目別)")
|
76 |
|
77 |
+
prefecture = st.selectbox("都道府県", list(prefectures.keys()))
|
78 |
|
79 |
gdf = get_geom_data(prefecture)
|
80 |
|
|
|
92 |
else:
|
93 |
gdf_filtered = gdf
|
94 |
|
95 |
+
selected_attribute = "FRAC_VEG"
|
|
|
96 |
|
97 |
# Custom CSS to create a box around the color scale controls
|
98 |
st.markdown("""
|
|
|
108 |
|
109 |
# Color scale controls in an expander
|
110 |
with st.expander("カラースケール設定", expanded=True):
|
111 |
+
st.markdown('<div class="color-scale-box">', unsafe_allow_html=True)
|
112 |
col1, col2, col3, col4 = st.columns(4)
|
113 |
with col1:
|
114 |
+
n_colors = st.slider("分割数", min_value=2, max_value=20, value=5)
|
115 |
with col2:
|
116 |
alpha = st.slider("透過率", min_value=0.0, max_value=1.0, value=0.8, step=0.1)
|
117 |
with col3:
|
118 |
+
vmin = st.number_input("最小値", value=0.0, step=0.1)
|
119 |
with col4:
|
120 |
+
vmax = st.number_input("最大値", value=1.0, step=0.1)
|
121 |
st.markdown('</div>', unsafe_allow_html=True)
|
122 |
|
123 |
# Other controls
|
|
|
173 |
layers=[layer],
|
174 |
initial_view_state=view_state,
|
175 |
map_style="mapbox://styles/mapbox/light-v9",
|
176 |
+
tooltip={"text": "{CITY_NAME_x} {S_NAME_x}\n{" + selected_attribute + "}: {" + selected_attribute + "}"}
|
177 |
)
|
178 |
|
179 |
st.pydeck_chart(r)
|
|
|
189 |
st.image(f"data:image/png;base64,{legend_img}", caption="Color Scale", use_column_width=True)
|
190 |
|
191 |
if st.checkbox("Show raw data"):
|
192 |
+
st.write(gdf_filtered[['CITY_NAME_x', 'S_NAME_x', selected_attribute]])
|
193 |
+
|
194 |
st.markdown(
|
195 |
"""
|
196 |
**データソース**
|