| | import streamlit as st |
| | import pandas as pd |
| | import openpyxl |
| | |
| | @st.cache_data |
| | def load_data(file_path): |
| | return pd.read_excel(file_path) |
| |
|
| | |
| | file_path = "BullSale.xlsx" |
| |
|
| | |
| | columns_to_display = [ |
| | "Animal ID", "Name", "Sex", "Birth Date", |
| | "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: |
| | |
| | data = load_data(file_path) |
| |
|
| | |
| | if "Type" not in data.columns: |
| | st.error("The 'Type' column is missing. Please check your file.") |
| | else: |
| | st.title("Bull Sale Inventory Dashboard") |
| |
|
| | |
| | types = data["Type"].unique() |
| |
|
| | |
| | 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, |
| | ) |
| |
|
| | if selected_types: |
| | for selected_type in selected_types: |
| | |
| | filtered_data = data[data["Type"] == selected_type] |
| |
|
| | |
| | st.subheader(f"{selected_type} Inventory") |
| | st.dataframe( |
| | filtered_data[columns_to_display], |
| | use_container_width=True |
| | ) |
| |
|
| | |
| | @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}") |
| |
|