awacke1's picture
Update app.py
12138f7
raw
history blame
1.48 kB
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Function to plot the map
def plot_map(data):
# Create a choropleth map as a base
fig = px.choropleth(locations=data['State'], locationmode="USA-states", scope="usa")
# Add a scatter plot on top to show the corporation labels
for index, row in data.iterrows():
fig.add_trace(go.Scattergeo(
lon=[row['Longitude']],
lat=[row['Latitude']],
text=f"{row['Corporation']} - ${row['Revenue']}B",
mode='text',
))
# Set the title
fig.update_layout(title="Top Corporations by State in the United States")
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 or use the default CSV file
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 the default CSV file if no files are uploaded
data = pd.read_csv('corporations_data.csv')
st.plotly_chart(plot_map(data))