awacke1 commited on
Commit
a5f19b3
·
1 Parent(s): 5c3e54a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -42
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
- from folium import Marker
5
- from streamlit_folium import folium_static
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
- def display_map(locations):
 
22
  # Create a folium map centered in Iceland
23
- iceland_map = folium.Map(location=[64.9631, -19.0208], zoom_start=6)
24
 
25
- # Add markers for the top 10 locations for viewing Northern Lights
26
- for location in locations:
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
- # Streamlit app
35
- st.title("Top 10 Locations to View Northern Lights in Iceland")
36
 
37
- # Textbox
38
- user_text = st.text_input("Enter your text:")
 
 
 
 
39
 
40
- # Dial
41
- dial_value = st.slider("Select a value:", 0, 100)
42
 
43
- # Four-direction button array
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
- # Display Folium map
56
- st.write("Top 10 locations for viewing the Northern Lights in Iceland:")
57
- folium_map = display_map(northern_lights_locations)
58
- # from streamlit_folium import st_folium
59
 
60
- # center on Liberty Bell, add marker
61
- m = folium.Map(location=[39.949610, -75.150282], zoom_start=16)
62
- folium.Marker(
63
- [39.949610, -75.150282], popup="Liberty Bell", tooltip="Liberty Bell"
64
- ).add_to(m)
65
 
66
- # call to render Folium map in Streamlit
67
- st_data = st_folium(m, width=725)
68
- folium_static(folium_map)
 
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
  )