File size: 1,478 Bytes
f542e7e
017ce74
 
12138f7
017ce74
dab3650
 
12138f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dab3650
 
f542e7e
 
017ce74
 
 
 
0631b4d
 
 
081bf5b
0631b4d
 
 
 
 
 
 
081bf5b
 
017ce74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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))