import streamlit as st import csv import os import random def save_data(name, email, phone): with open('community.csv', mode='a') as csv_file: fieldnames = ['Name', 'Email', 'Phone'] writer = csv.DictWriter(csv_file, fieldnames=fieldnames) if os.stat('community.csv').st_size == 0: writer.writeheader() writer.writerow({'Name': name, 'Email': email, 'Phone': phone}) with open(f'{name}.txt', mode='w') as file: file.write(f'Name: {name}\nEmail: {email}\nPhone: {phone}\n') def reset_data(): os.remove('community.csv') for file in os.listdir(): if file.endswith('.txt'): os.remove(file) def show_data(): count = 0 with open('community.csv', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: count += 1 if count == 3: st.write(f'{row["Name"]}: {row["Email"]} - {row["Phone"]}') count = 0 def app(): st.title('Community Hub Form') name = st.text_input('Name', key='name_input') email = st.text_input('Email', key='email_input') phone = st.text_input('Phone', key='phone_input') if st.button('Submit', key='submit_button'): save_data(name, email, phone) st.success('Form submitted!') if st.button('Reset', key='reset_button'): reset_data() st.success('Data reset!') if st.button('Show data', key='show_data_button'): show_data() st.write('Emails/SMS') with open('community.csv', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: name = row['Name'] email = row['Email'] phone = row['Phone'] st.write(f'{name}: {email} - {phone}') if st.button('Reply', key=f'reply_{name}'): st.text_input(f'Reply to {name}', key=f'reply_input_{name}') if st.button(f'Vote up {name}', key=f'vote_up_{name}'): st.success(f'{name} has been voted up!') if st.button(f'No thanks to {name}', key=f'vote_down_{name}'): st.warning(f'{name} has been voted down!') with open(f'{name}.txt', mode='w') as file: file.write(f'Life points: 0\n') st.write('') st.write('Add tip') tip = st.text_input('Tip', key='tip_input') if st.button('Submit tip', key='submit_tip_button'): emoji = random.choice(['👍', '👌', '👏', 'ðŸ’Ą']) with open(f'{name}.txt', mode='a') as file: file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n') st.success('Tip submitted!') import streamlit as st import pandas as pd import plotly.graph_objects as go import plotly.express as px # Define the states and conditions of interest states = ["Minnesota", "Florida", "California", "Washington", "Maine", "Texas"] top_n = 10 # Define the list dictionary of top 10 health conditions descending by cost, with emojis health_conditions = [ {"condition": "💔 Heart disease", "emoji": "💗", "spending": 214.3}, {"condition": "ðŸĪ• Trauma-related disorders", "emoji": "🚑", "spending": 198.6}, {"condition": "ðŸĶ€ Cancer", "emoji": "🎗ïļ", "spending": 171.0}, {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8}, {"condition": "ðŸĶī Osteoarthritis and joint disorders", "emoji": "ðŸĨ", "spending": 142.4}, {"condition": "💉 Diabetes", "emoji": "ðŸĐļ", "spending": 107.4}, {"condition": "ðŸŦ Chronic obstructive pulmonary disease and asthma", "emoji": "ðŸŦ€", "spending": 91.0}, {"condition": "ðŸĐš Hypertension", "emoji": "💉", "spending": 83.9}, {"condition": "🔎 Hyperlipidemia", "emoji": "🔎", "spending": 83.9}, {"condition": "ðŸĶī Back problems", "emoji": "🧍", "spending": 67.0} ] # Total the spending values total_spending = sum([hc["spending"] for hc in health_conditions]) # Create a DataFrame from the list dictionary df_top_conditions = pd.DataFrame(health_conditions) # Create the map graph using Plotly Express locations = ["CA", "FL", "MN", "WA", "ME", "TX"] fig_map = px.choropleth(locations=locations, locationmode="USA-states", color=[1, 2, 3, 4, 5, 6], scope="usa") fig_map.update_layout(geo=dict(bgcolor= "rgba(0, 0, 0, 0)", lakecolor="rgb(255, 255, 255)")) # Create the bar chart using Plotly Graph Objects fig_bar = go.Figure(go.Bar(x=df_top_conditions["emoji"] + " " + df_top_conditions["condition"], y=df_top_conditions["spending"], marker_color="#1f77b4")) fig_bar.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)", yaxis_title="Spending ($B)", plot_bgcolor='rgba(0,0,0,0)', xaxis=dict(showgrid=False), yaxis=dict(showgrid=False)) # Display the map and the bar chart in Streamlit col1, col2 = st.columns([2, 1]) with col1: st.plotly_chart(fig_map, use_container_width=True) with col2: st.plotly_chart(fig_bar, use_container_width=True) if __name__ == '__main__': app()