MatthewMec commited on
Commit
42d3faf
·
1 Parent(s): a9064ad
Files changed (2) hide show
  1. BullSale.xlsx +0 -0
  2. app.py +75 -0
BullSale.xlsx ADDED
Binary file (29.9 kB). View file
 
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ # Load data from Excel file
5
+ @st.cache_data
6
+ def load_data(file_path):
7
+ return pd.read_excel(file_path)
8
+
9
+ # Path to the Excel file
10
+ file_path = "BullSale.xlsx"
11
+
12
+ # Columns to display
13
+ columns_to_display = [
14
+ "Animal ID", "Name", "Sex", "Birth Date", # Static columns
15
+ "ProS", "ProS%", "HerdBuilder", "HerdBuilder %", "GridMaster", "GridMaster %",
16
+ "CED", "CED Acc", "CED %", "BW", "BW Acc", "BW %", "WW", "WW Acc", "WW %", "YW",
17
+ "YW Acc", "YW %", "ADG", "ADG Acc", "ADG %", "DMI", "DMI Acc", "DMI %", "Milk",
18
+ "Milk Acc", "Milk %", "ME", "ME Acc", "ME %", "HPG", "HPG Acc", "HPG %", "CEM",
19
+ "CEM Acc", "CEM %", "Stay", "Stay Acc", "Stay %", "Marb", "Marb Acc", "Marb %",
20
+ "YG", "YG Acc", "YG %", "CW", "CW Acc", "CW %", "RE", "RE Acc", "RE %", "BF",
21
+ "BF Acc", "BF %", "Actual BW", "WW Date", "Actual WW", "Sire ID", "Sire Reg #",
22
+ ]
23
+
24
+ try:
25
+ # Load data
26
+ data = load_data(file_path)
27
+
28
+ # Ensure Type column exists
29
+ if "Type" not in data.columns:
30
+ st.error("The 'Type' column is missing. Please check your file.")
31
+ else:
32
+ st.title("Bull Sale Inventory Dashboard")
33
+
34
+ # Get unique bull types
35
+ types = data["Type"].unique()
36
+
37
+ # Sidebar for selecting bull types
38
+ st.sidebar.header("Filter by Bull Type")
39
+ selected_types = st.sidebar.multiselect(
40
+ "Select the type(s) of bulls you're interested in:",
41
+ options=types,
42
+ default=types, # Select all types by default
43
+ )
44
+
45
+ if selected_types:
46
+ for selected_type in selected_types:
47
+ # Filter data by each selected type
48
+ filtered_data = data[data["Type"] == selected_type]
49
+
50
+ # Display the editable data table for each selected type using st.dataframe
51
+ st.subheader(f"{selected_type} Inventory")
52
+ st.dataframe(
53
+ filtered_data[columns_to_display],
54
+ use_container_width=True
55
+ )
56
+
57
+ # Download the edited data for this type
58
+ @st.cache_data
59
+ def convert_df_to_csv(df):
60
+ return df.to_csv(index=False).encode("utf-8")
61
+
62
+ csv = convert_df_to_csv(filtered_data)
63
+ st.download_button(
64
+ label=f"Download {selected_type} Data as CSV",
65
+ data=csv,
66
+ file_name=f"{selected_type}_data.csv",
67
+ mime="text/csv",
68
+ )
69
+ else:
70
+ st.info("Please select at least one bull type to view the data.")
71
+
72
+ except FileNotFoundError:
73
+ st.error(f"The file at {file_path} was not found. Please check the path and try again.")
74
+ except Exception as e:
75
+ st.error(f"An error occurred: {e}")