Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.markdown("""
|
4 |
+
π Welcome to my guide on creating a streamlit application for tracking health care problems and conditions! π¨ββοΈπ©ββοΈ
|
5 |
+
|
6 |
+
π Here's a step by step outline to get you started:
|
7 |
+
|
8 |
+
Step 1: Install Streamlit π₯
|
9 |
+
First things first, let's make sure we have Streamlit installed! Here's how:
|
10 |
+
|
11 |
+
add a requirements.txt file with each library you will need including:
|
12 |
+
streamlit
|
13 |
+
pandas
|
14 |
+
geopy
|
15 |
+
folium
|
16 |
+
|
17 |
+
Step 2: Create a new file π
|
18 |
+
Now that Streamlit is installed, let's create a new Python file for our application.
|
19 |
+
|
20 |
+
Here's how:
|
21 |
+
Create a new app.py file.
|
22 |
+
|
23 |
+
|
24 |
+
Step 3: Import the necessary libraries π
|
25 |
+
The requirements.txt will be executed with pip install -r requirements.txt
|
26 |
+
|
27 |
+
This will import the following libraries:
|
28 |
+
streamlit (for building the app)
|
29 |
+
pandas (for working with data)
|
30 |
+
geopy (for geocoding and distance calculations)
|
31 |
+
folium (for creating maps)
|
32 |
+
|
33 |
+
Step 4: Create the user interface π₯οΈ
|
34 |
+
Now let's create the user interface for our app! Here's how:
|
35 |
+
|
36 |
+
Use the streamlit library to create a title for the app
|
37 |
+
Create an input field for the user to enter their location
|
38 |
+
Create checkboxes for the health care problems and conditions the user is interested in
|
39 |
+
Use the streamlit library to create a button to submit the user's input
|
40 |
+
Step 5: Retrieve and filter data π
|
41 |
+
Now that we have the user's input, let's retrieve and filter the data we need. Here's how:
|
42 |
+
|
43 |
+
Use the pandas library to read in a dataset of health care providers and facilities in the area
|
44 |
+
Use the geopy library to geocode the user's location
|
45 |
+
Calculate the distance between the user's location and each provider/facility in the dataset
|
46 |
+
Filter the dataset based on the user's selected health care problems/conditions
|
47 |
+
Step 6: Display the results π
|
48 |
+
Finally, let's display the results to the user! Here's how:
|
49 |
+
|
50 |
+
Use the folium library to create a map with markers for each provider/facility in the filtered dataset
|
51 |
+
Display the map to the user
|
52 |
+
Use the streamlit library to display a table with information about each provider/facility in the filtered dataset
|
53 |
+
π And that's it! You now have a streamlit application for tracking health care problems and conditions and identifying providers and facilities in the user's area. Good luck building your app! π
|
54 |
+
|
55 |
+
|
56 |
+
""")
|
57 |
+
|
58 |
+
|
59 |
+
import streamlit as st
|
60 |
+
import pandas as pd
|
61 |
+
from geopy.geocoders import Nominatim
|
62 |
+
import folium
|
63 |
+
|
64 |
+
# Set page title
|
65 |
+
st.set_page_config(page_title="Healthcare Providers Map")
|
66 |
+
|
67 |
+
# Define function to get geolocation data from user's input
|
68 |
+
def get_location(address):
|
69 |
+
geolocator = Nominatim(user_agent="my_app")
|
70 |
+
location = geolocator.geocode(address)
|
71 |
+
return (location.latitude, location.longitude)
|
72 |
+
|
73 |
+
# Define function to filter providers by selected health conditions
|
74 |
+
def filter_providers(df, conditions):
|
75 |
+
return df[df['Conditions'].apply(lambda x: any(item for item in conditions if item in x))]
|
76 |
+
|
77 |
+
# Load data
|
78 |
+
#df = pd.read_csv('healthcare_providers.csv')
|
79 |
+
df = pd.read_csv('minnesota_providers.csv')
|
80 |
+
|
81 |
+
|
82 |
+
# Create UI elements
|
83 |
+
st.title("Healthcare Providers Map")
|
84 |
+
|
85 |
+
location_input = st.text_input("Enter your address to find healthcare providers in your area:")
|
86 |
+
conditions_checkboxes = st.sidebar.multiselect("Select the health conditions you are interested in:",
|
87 |
+
['Asthma', 'Cancer', 'Diabetes', 'Heart disease', 'High blood pressure'])
|
88 |
+
|
89 |
+
if st.button("Find Providers"):
|
90 |
+
# Get user's location
|
91 |
+
user_location = get_location(location_input)
|
92 |
+
|
93 |
+
# Filter providers based on selected conditions
|
94 |
+
filtered_providers = filter_providers(df, conditions_checkboxes)
|
95 |
+
|
96 |
+
# Create map with markers for each provider
|
97 |
+
m = folium.Map(location=user_location, zoom_start=12)
|
98 |
+
|
99 |
+
for index, row in filtered_providers.iterrows():
|
100 |
+
folium.Marker([row['Latitude'], row['Longitude']], popup=row['Name']).add_to(m)
|
101 |
+
|
102 |
+
# Display map to user
|
103 |
+
folium_static(m)
|
104 |
+
|
105 |
+
|
106 |
+
import pandas as pd
|
107 |
+
|
108 |
+
# Define column names for the providers
|
109 |
+
columns = ['Name', 'Address', 'City', 'State', 'Zipcode', 'Phone', 'Website']
|
110 |
+
|
111 |
+
# Define the list of providers as a list of lists
|
112 |
+
providers = [
|
113 |
+
['Minnesota Community Care', '570 University Avenue', 'Saint Paul', 'MN', '55103', '(651) 602-7500', 'https://mncc.org/'],
|
114 |
+
['Hennepin Healthcare', '701 Park Avenue', 'Minneapolis', 'MN', '55415', '(612) 873-3000', 'https://www.hennepinhealthcare.org/'],
|
115 |
+
['Allina Health', '800 East 28th Street', 'Minneapolis', 'MN', '55407', '(612) 863-4000', 'https://www.allinahealth.org/'],
|
116 |
+
['Fairview Health Services', '2450 Riverside Avenue', 'Minneapolis', 'MN', '55454', '(612) 672-7000', 'https://www.fairview.org/'],
|
117 |
+
['HealthPartners', '8170 33rd Avenue South', 'Bloomington', 'MN', '55425', '(952) 883-6000', 'https://www.healthpartners.com/'],
|
118 |
+
['Mayo Clinic Health System', '1216 Second Street Southwest', 'Rochester', 'MN', '55902', '(507) 266-7890', 'https://www.mayoclinic.org/'],
|
119 |
+
]
|
120 |
+
|
121 |
+
# Create a DataFrame from the providers list
|
122 |
+
df = pd.DataFrame(providers, columns=columns)
|
123 |
+
|
124 |
+
# Save the DataFrame as a CSV file
|
125 |
+
df.to_csv('minnesota_providers.csv', index=False)
|
126 |
+
|
127 |
+
|