awacke1 commited on
Commit
081bf5b
·
1 Parent(s): 0cc9b6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -31
app.py CHANGED
@@ -1,34 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
- import csv
5
- import base64
6
-
7
- # Default data for top two corporations per state
8
- states = [
9
- "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
10
- "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
11
- "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
12
- "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
13
- "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
14
- "New Hampshire", "New Jersey", "New Mexico", "New York",
15
- "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
16
- "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
17
- "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
18
- "West Virginia", "Wisconsin", "Wyoming"
19
- ]
20
-
21
- corporations_data = []
22
- for state in states:
23
- corporations_data.append((state, f'{state}Corp1', 100))
24
- corporations_data.append((state, f'{state}Corp2', 50))
25
-
26
- # Function to plot the map
27
- def plot_map(data):
28
- fig = px.choropleth(locations=data['State'], locationmode="USA-states", color=data['Revenue'],
29
- scope="usa", title="Top Corporations by State in the United States",
30
- hover_name=data['Corporation'], hover_data=['Revenue'])
31
- return fig
32
 
33
  # Streamlit app
34
  st.title('Top Corporations by State in the United States')
@@ -39,7 +11,7 @@ uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=Tru
39
  # Display map button
40
  display_map_button = st.button('Display Map of CSV Data 🗺️')
41
 
42
- # If button is clicked, use uploaded files to generate maps
43
  if display_map_button:
44
  if uploaded_files:
45
  for uploaded_file in uploaded_files:
@@ -47,6 +19,13 @@ if display_map_button:
47
  st.write(f"Map for {uploaded_file.name}")
48
  st.plotly_chart(plot_map(data))
49
  else:
50
- # Use default data if no files are uploaded
51
- data = pd.DataFrame(corporations_data, columns=['State', 'Corporation', 'Revenue'])
52
  st.plotly_chart(plot_map(data))
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  # Streamlit app
6
  st.title('Top Corporations by State in the United States')
 
11
  # Display map button
12
  display_map_button = st.button('Display Map of CSV Data 🗺️')
13
 
14
+ # If button is clicked, use uploaded files to generate maps or use the default CSV file
15
  if display_map_button:
16
  if uploaded_files:
17
  for uploaded_file in uploaded_files:
 
19
  st.write(f"Map for {uploaded_file.name}")
20
  st.plotly_chart(plot_map(data))
21
  else:
22
+ # Use the default CSV file if no files are uploaded
23
+ data = pd.read_csv('corporations_data.csv')
24
  st.plotly_chart(plot_map(data))
25
+
26
+ # Function to plot the map
27
+ def plot_map(data):
28
+ fig = px.choropleth(locations=data['State'], locationmode="USA-states", color=data['Revenue'],
29
+ scope="usa", title="Top Corporations by State in the United States",
30
+ hover_name=data['Corporation'], hover_data=['Revenue'])
31
+ return fig