Spaces:
No application file
No application file
Update src/streamlit_app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import osimport pandas as pdimport streamlit as st# Import modulesfrom scripts.featureEngineering import add_flight_dayfrom scripts.stats import tidy_from_wide, analyze_r1_vs_Lfrom scripts.graphMaking import make_figure# Load Datadef list_final_data(folder="final_data"):"""Return list of CSV files in final_data folder."""return [f for f in os.listdir(folder) if f.endswith(".csv")]def load_final_data(fname, folder="final_data"):"""Load selected CSV file as pandas DataFrame."""path = os.path.join(folder, fname)return pd.read_csv(path)# Main Appdef main():st.title("Astronaut Biochemistry Dashboard")# 1. Sidebar file selectionst.sidebar.header("Data Selection")csv_files = list_final_data()if not csv_files:st.error("No CSV files found in final_data/")returnselected_file = st.sidebar.selectbox("Choose dataset", csv_files)df_raw = load_final_data(selected_file)st.write(f"Loaded file: **{selected_file}**")# 2. Clean with feature engineeringdf_clean = add_flight_day(df_raw)# 3. Transform to tidy format + run statstidy_df = tidy_from_wide(df_clean)stats_df = analyze_r1_vs_L(tidy_df)# 4. Sidebar user selectionsst.sidebar.header("Plot Controls")analyte = st.sidebar.selectbox("Select Analyte",options=tidy_df["analyte"].unique().tolist(),index=tidy_df["analyte"].unique().tolist().index("sodium")if "sodium" in tidy_df["analyte"].unique() else 0)astronauts = st.sidebar.multiselect("Select Astronauts",# Normalize IDs to uppercase for consistencyoptions=sorted([a.upper() for a in tidy_df["astronautID"].unique().tolist()]),default=[])astronauts = [a.upper() for a in astronauts]sex_filter = st.sidebar.radio("Sex Filter",["All", "Male", "Female"],index=0)show_error = st.sidebar.radio("Error Band",["None", "within", "group"],index=0)show_error = None if show_error == "None" else show_error# Unify filters: Astronauts take priority, else fall back to sex filterif astronauts:astronaut_filter = astronautselif sex_filter != "All":astronaut_filter = sex_filterelse:astronaut_filter = None# 5. Generate figureif analyte:fig = make_figure(tidy_df=tidy_df,stats_df=stats_df,analytes=[analyte],astronaut_filter=astronaut_filter,show_error=show_error)st.plotly_chart(fig, use_container_width=True)else:st.warning("Please select at least one analyte to plot.")# 6. Optional: preview datawith st.expander("Preview Data"):st.dataframe(tidy_df.head(20))if __name__ == "__main__":main()
src/streamlit_app.py+97-37