Spaces:
Runtime error
Runtime error
feat: tab separation
Browse files- pages/1_π_Plotting.py +49 -42
pages/1_π_Plotting.py
CHANGED
@@ -7,6 +7,8 @@ st.header("Plotting Time Series Data")
|
|
7 |
st.markdown("Users can load their time-series data in **.csv** format and select a particular feature and plot-type.\
|
8 |
Go ahead and use the sidebar on the left to upload your data files to start visualizing it!")
|
9 |
|
|
|
|
|
10 |
# Load and config
|
11 |
with st.sidebar:
|
12 |
plot = st.radio("Select the kind of visualization:",('Feature collection', 'Users comparison', 'Data distribution'))
|
@@ -22,46 +24,51 @@ with st.sidebar:
|
|
22 |
st.session_state['df'] = df
|
23 |
st.success("Your data has been successfully loaded! π€")
|
24 |
|
25 |
-
|
26 |
-
st.
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
df_base = st.session_state.df if 'df' in st.session_state else pd.DataFrame()
|
32 |
-
n = len(df_base)
|
33 |
-
col1, col2 = st.columns(2)
|
34 |
-
|
35 |
-
# Prepare data
|
36 |
-
if not df_base.empty and n:
|
37 |
-
with col1:
|
38 |
-
st.info(f"Your data has {n} samples.")
|
39 |
-
slider_range = list(range(n))
|
40 |
-
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)
|
41 |
-
plot_it = st.button("Plot now! π")
|
42 |
-
if plot_it:
|
43 |
-
st.snow()
|
44 |
-
feature = "relative_pupil_dilation"
|
45 |
-
df_plot = df_base.head(n_plot)
|
46 |
-
df_plot = [ini_list.strip('][').split(',') for ini_list in df_plot[feature]]
|
47 |
-
df_plot = pd.DataFrame(df_plot)
|
48 |
-
df_plot.columns = [str(column) for column in range(len(df_plot.columns))]
|
49 |
-
if 'df_plot' not in st.session_state:
|
50 |
-
st.session_state['df_plot'] = df_plot
|
51 |
-
|
52 |
-
# Draw plot
|
53 |
-
if 'df_plot' in st.session_state:
|
54 |
-
with st.spinner(f"Drawing plot to visualize {plot.lower()}"):
|
55 |
-
st.caption("Your visualization:")
|
56 |
-
df_plot_t = df_plot.copy(deep=True).transpose()
|
57 |
-
df_plot_t.columns = [str(column) for column in range(len(df_plot_t.columns))]
|
58 |
-
st.line_chart(df_plot_t, y=list(df_plot_t.columns), height=400, width=600)
|
59 |
-
st.dataframe(df_plot_t)
|
60 |
-
with st.expander("See explanation"):
|
61 |
-
st.caption("The chart above shows...")
|
62 |
-
elif df_base.empty and file:
|
63 |
-
st.warning("Consider running outlier detection to clean your data!", icon="β οΈ")
|
64 |
|
65 |
-
st.
|
66 |
-
|
67 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
st.markdown("Users can load their time-series data in **.csv** format and select a particular feature and plot-type.\
|
8 |
Go ahead and use the sidebar on the left to upload your data files to start visualizing it!")
|
9 |
|
10 |
+
tab1, tab2 = st.tabs(["Main", "Demo"])
|
11 |
+
|
12 |
# Load and config
|
13 |
with st.sidebar:
|
14 |
plot = st.radio("Select the kind of visualization:",('Feature collection', 'Users comparison', 'Data distribution'))
|
|
|
24 |
st.session_state['df'] = df
|
25 |
st.success("Your data has been successfully loaded! π€")
|
26 |
|
27 |
+
with tab1:
|
28 |
+
if 'df' in st.session_state:
|
29 |
+
st.caption("Your uploaded data:")
|
30 |
+
st.dataframe(st.session_state.df)
|
31 |
+
else:
|
32 |
+
st.caption("Upload your data using the sidebar and select a plot-type to start :sunglasses:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
df_base = st.session_state.df if 'df' in st.session_state else pd.DataFrame()
|
35 |
+
n = len(df_base)
|
36 |
+
col1, col2 = st.columns(2)
|
37 |
+
|
38 |
+
# Prepare data
|
39 |
+
if not df_base.empty and n:
|
40 |
+
with col1:
|
41 |
+
st.info(f"Your data has {n} samples.")
|
42 |
+
slider_range = list(range(n))
|
43 |
+
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)
|
44 |
+
plot_it = st.button("Plot now! π")
|
45 |
+
if plot_it:
|
46 |
+
st.snow()
|
47 |
+
feature = "relative_pupil_dilation"
|
48 |
+
df_plot = df_base.head(n_plot)
|
49 |
+
df_plot = [ini_list.strip('][').split(',') for ini_list in df_plot[feature]]
|
50 |
+
df_plot = pd.DataFrame(df_plot)
|
51 |
+
df_plot.columns = [str(column) for column in range(len(df_plot.columns))]
|
52 |
+
if 'df_plot' not in st.session_state:
|
53 |
+
st.session_state['df_plot'] = df_plot
|
54 |
+
|
55 |
+
# Draw plot
|
56 |
+
if 'df_plot' in st.session_state:
|
57 |
+
with st.spinner(f"Drawing plot to visualize {plot.lower()}"):
|
58 |
+
st.caption("Your visualization:")
|
59 |
+
df_plot_t = df_plot.copy(deep=True).transpose()
|
60 |
+
df_plot_t.columns = [str(column) for column in range(len(df_plot_t.columns))]
|
61 |
+
st.line_chart(df_plot_t, y=list(df_plot_t.columns), height=400, width=600)
|
62 |
+
st.dataframe(df_plot_t)
|
63 |
+
with st.expander("See explanation"):
|
64 |
+
st.caption("The chart above shows...")
|
65 |
+
elif df_base.empty and file:
|
66 |
+
st.warning("Consider running outlier detection to clean your data!", icon="β οΈ")
|
67 |
+
|
68 |
+
st.caption(f"developer:: session_state keys: {list(st.session_state.keys())}")
|
69 |
+
st.caption(f"what is the meaning of the x-axis, add to explanation")
|
70 |
+
st.caption(f"add sample data demo in another tab")
|
71 |
+
|
72 |
+
# demo
|
73 |
+
with tab2:
|
74 |
+
st.caption("demo under construction π§")
|