Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import plotly.express as px | |
import csv | |
import base64 | |
# Default data for top two corporations per state | |
states = [ | |
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", | |
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", | |
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", | |
"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", | |
"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", | |
"New Hampshire", "New Jersey", "New Mexico", "New York", | |
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", | |
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", | |
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", | |
"West Virginia", "Wisconsin", "Wyoming" | |
] | |
corporations_data = [] | |
for state in states: | |
corporations_data.append((state, f'{state}Corp1', 100)) | |
corporations_data.append((state, f'{state}Corp2', 50)) | |
# Function to plot the map | |
def plot_map(data): | |
fig = px.choropleth(locations=data['State'], locationmode="USA-states", color=data['Revenue'], | |
scope="usa", title="Top Corporations by State in the United States", | |
hover_name=data['Corporation'], hover_data=['Revenue']) | |
return fig | |
# Streamlit app | |
st.title('Top Corporations by State in the United States') | |
# Upload CSV | |
uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True, type="csv") | |
# Display map button | |
display_map_button = st.button('Display Map of CSV Data 🗺️') | |
# If button is clicked, use uploaded files to generate maps | |
if display_map_button: | |
if uploaded_files: | |
for uploaded_file in uploaded_files: | |
data = pd.read_csv(uploaded_file) | |
st.write(f"Map for {uploaded_file.name}") | |
st.plotly_chart(plot_map(data)) | |
else: | |
# Use default data if no files are uploaded | |
data = pd.DataFrame(corporations_data, columns=['State', 'Corporation', 'Revenue']) | |
st.plotly_chart(plot_map(data)) | |