File size: 2,817 Bytes
42d3faf
 
f480eb4
42d3faf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import streamlit as st
import pandas as pd
import openpyxl
# Load data from Excel file
@st.cache_data
def load_data(file_path):
    return pd.read_excel(file_path)

# Path to the Excel file
file_path = "BullSale.xlsx"

# Columns to display
columns_to_display = [
    "Animal ID", "Name", "Sex", "Birth Date",  # Static columns
    "ProS", "ProS%", "HerdBuilder", "HerdBuilder %", "GridMaster", "GridMaster %",
    "CED", "CED Acc", "CED %", "BW", "BW Acc", "BW %", "WW", "WW Acc", "WW %", "YW",
    "YW Acc", "YW %", "ADG", "ADG Acc", "ADG %", "DMI", "DMI Acc", "DMI %", "Milk",
    "Milk Acc", "Milk %", "ME", "ME Acc", "ME %", "HPG", "HPG Acc", "HPG %", "CEM",
    "CEM Acc", "CEM %", "Stay", "Stay Acc", "Stay %", "Marb", "Marb Acc", "Marb %",
    "YG", "YG Acc", "YG %", "CW", "CW Acc", "CW %", "RE", "RE Acc", "RE %", "BF",
    "BF Acc", "BF %", "Actual BW", "WW Date", "Actual WW", "Sire ID", "Sire Reg #",
]

try:
    # Load data
    data = load_data(file_path)

    # Ensure Type column exists
    if "Type" not in data.columns:
        st.error("The 'Type' column is missing. Please check your file.")
    else:
        st.title("Bull Sale Inventory Dashboard")

        # Get unique bull types
        types = data["Type"].unique()

        # Sidebar for selecting bull types
        st.sidebar.header("Filter by Bull Type")
        selected_types = st.sidebar.multiselect(
            "Select the type(s) of bulls you're interested in:",
            options=types,
            default=types,  # Select all types by default
        )

        if selected_types:
            for selected_type in selected_types:
                # Filter data by each selected type
                filtered_data = data[data["Type"] == selected_type]

                # Display the editable data table for each selected type using st.dataframe
                st.subheader(f"{selected_type} Inventory")
                st.dataframe(
                    filtered_data[columns_to_display],
                    use_container_width=True
                )

                # Download the edited data for this type
                @st.cache_data
                def convert_df_to_csv(df):
                    return df.to_csv(index=False).encode("utf-8")

                csv = convert_df_to_csv(filtered_data)
                st.download_button(
                    label=f"Download {selected_type} Data as CSV",
                    data=csv,
                    file_name=f"{selected_type}_data.csv",
                    mime="text/csv",
                )
        else:
            st.info("Please select at least one bull type to view the data.")

except FileNotFoundError:
    st.error(f"The file at {file_path} was not found. Please check the path and try again.")
except Exception as e:
    st.error(f"An error occurred: {e}")