import streamlit as st import pandas as pd import time st.header("Plotting Time Series Data") st.markdown("Users can load their time-series data in **.csv** format and select a particular feature and plot-type.\ Go ahead and use the sidebar on the left to upload your data files and to start visualizing it!") with st.sidebar: plot = st.radio("Select the kind of visualization:",('Feature collection', 'Users comparison', 'Data distribution')) file = st.file_uploader("Load CSV file", accept_multiple_files = False) if file: df = pd.read_csv(file, index_col = False) # df.index = df['Unnamed: 0'].tolist() try: del df['Unnamed: 0'] except KeyError: pass if 'df' not in st.session_state: st.session_state['df'] = df st.success("Your data has been successfully loaded! 🤗") if 'df' in list(st.session_state.keys()): st.caption("Your uploaded data:") st.dataframe(st.session_state.df) else: st.caption("Upload your data using the sidebar and select a plot-type to start :sunglasses:") df_base = st.session_state.df if 'df' in list(st.session_state.keys()) else pd.DataFrame() n = len(df_base) col1, col2 = st.columns(2) if not df_base.empty: with col1: st.info(f"Your data has {n} samples.") slider_range = list(range(n)) n_plot = st.slider("How many samples do you want to plot in the same graph", slider_range[0]+1, slider_range[-1]+1, 5) st.write(f"Action: {plot} using {n_plot} samples") plot_it = st.button("Plot now! 📊") if plot_it: st.snow() feature = "relative_pupil_dilation" df_plot = df_base.head(n_plot) df_plot = [ini_list.strip('][').split(',') for ini_list in df_plot[feature]] st.caption("The visualized data:") df_plot = pd.DataFrame(df_plot) st.dataframe(df_plot) if 'df_plot' not in st.session_state: st.session_state['df_plot'] = df_plot with st.expander("See explanation"): st.caption("The chart above shows...") # # with col2: if 'df_plot' in list(st.session_state.keys()): with st.spinner(f"Drawing plot to visualize {plot.lower()}"): st.caption("Your visualization:") st.dataframe(st.session_state.df_plot) st.line_chart(st.session_state.df_plot) st.dataframe(st.session_state.df_plot.transpose()) st.line_chart(st.session_state.df_plot.transpose()) elif df_base.empty and file: st.warning("Consider running outlier detection to clean your data!", icon="⚠️")