Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
# Northern.Lights.Map.Streamlit.Folium - write a streamlit python program that uses functions and user interface elements of a textbox, a dial, a four direction button array for up down left right and display a folium map with the data in python list dictionaries with these values: Aurora Spottings, Notifications on Nerthern Lights, Northern lights map location cities and countries for Iceland on a map written with folium for latitude and longitude of top ten places to view Northern Lights. Cite References as urls.
|
2 |
import streamlit as st
|
3 |
import folium
|
4 |
-
|
5 |
-
from
|
6 |
|
7 |
# Top 10 locations for viewing Northern Lights in Iceland
|
8 |
northern_lights_locations = [
|
@@ -18,54 +17,39 @@ northern_lights_locations = [
|
|
18 |
{"name": "Kirkjufell", "lat": 64.9426, "lon": -23.3061},
|
19 |
]
|
20 |
|
21 |
-
|
|
|
22 |
# Create a folium map centered in Iceland
|
23 |
-
iceland_map = folium.Map(location=[
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
Marker(
|
28 |
-
[location["lat"], location["lon"]],
|
29 |
-
popup=f"<b>{location['name']}</b>",
|
30 |
-
).add_to(iceland_map)
|
31 |
-
|
32 |
-
return iceland_map
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
|
37 |
-
#
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
dial_value = st.slider("Select a value:", 0, 100)
|
42 |
|
43 |
-
|
44 |
-
st.write("Four-direction button array:")
|
45 |
-
col1, col2, col3 = st.columns(3)
|
46 |
-
with col2:
|
47 |
-
st.button("Up")
|
48 |
-
with col1:
|
49 |
-
st.button("Left")
|
50 |
-
with col3:
|
51 |
-
st.button("Right")
|
52 |
-
with col2:
|
53 |
-
st.button("Down")
|
54 |
|
55 |
-
#
|
56 |
-
st.
|
57 |
-
folium_map = display_map(northern_lights_locations)
|
58 |
-
# from streamlit_folium import st_folium
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
[39.949610, -75.150282], popup="Liberty Bell", tooltip="Liberty Bell"
|
64 |
-
).add_to(m)
|
65 |
|
66 |
-
#
|
67 |
-
|
68 |
-
|
|
|
69 |
|
70 |
# Cite references
|
71 |
st.write(
|
@@ -73,6 +57,7 @@ st.write(
|
|
73 |
References:
|
74 |
- [Folium documentation](https://python-visualization.github.io/folium/)
|
75 |
- [Streamlit documentation](https://docs.streamlit.io/)
|
|
|
76 |
- [Top 10 locations](https://www.guidetoiceland.is/best-of-iceland/top-10-places-to-see-the-northern-lights)
|
77 |
"""
|
78 |
)
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import folium
|
3 |
+
import dask.dataframe as dd
|
4 |
+
from folium.plugins import MarkerCluster
|
5 |
|
6 |
# Top 10 locations for viewing Northern Lights in Iceland
|
7 |
northern_lights_locations = [
|
|
|
17 |
{"name": "Kirkjufell", "lat": 64.9426, "lon": -23.3061},
|
18 |
]
|
19 |
|
20 |
+
# Function to display the map
|
21 |
+
def display_map(locations, lat, lon):
|
22 |
# Create a folium map centered in Iceland
|
23 |
+
iceland_map = folium.Map(location=[lat, lon], zoom_start=6)
|
24 |
|
25 |
+
# Create a marker cluster group
|
26 |
+
marker_cluster = MarkerCluster().add_to(iceland_map)
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Create a Dask dataframe from the list of locations
|
29 |
+
dask_df = dd.from_pandas(pd.DataFrame(locations), npartitions=4)
|
30 |
|
31 |
+
# Add markers for the top 10 locations for viewing Northern Lights
|
32 |
+
def add_markers(row):
|
33 |
+
folium.Marker(
|
34 |
+
location=[row["lat"], row["lon"]],
|
35 |
+
popup=f"<b>{row['name']}</b>",
|
36 |
+
).add_to(marker_cluster)
|
37 |
|
38 |
+
dask_df.map_partitions(lambda df: df.apply(add_markers, axis=1)).compute()
|
|
|
39 |
|
40 |
+
return iceland_map
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# Streamlit app
|
43 |
+
st.title("Northern Lights Map in Iceland")
|
|
|
|
|
44 |
|
45 |
+
# User input for latitude and longitude
|
46 |
+
lat = st.number_input("Enter latitude:", value=64.9631, step=0.0001)
|
47 |
+
lon = st.number_input("Enter longitude:", value=-19.0208, step=0.0001)
|
|
|
|
|
48 |
|
49 |
+
# Display the map
|
50 |
+
st.write("Northern Lights Viewing Locations in Iceland:")
|
51 |
+
folium_map = display_map(northern_lights_locations, lat, lon)
|
52 |
+
st.folium_static(folium_map)
|
53 |
|
54 |
# Cite references
|
55 |
st.write(
|
|
|
57 |
References:
|
58 |
- [Folium documentation](https://python-visualization.github.io/folium/)
|
59 |
- [Streamlit documentation](https://docs.streamlit.io/)
|
60 |
+
- [Dask documentation](https://dask.org/)
|
61 |
- [Top 10 locations](https://www.guidetoiceland.is/best-of-iceland/top-10-places-to-see-the-northern-lights)
|
62 |
"""
|
63 |
)
|