|
11 | 11 | from streamlit_plotly_events import plotly_events
|
12 | 12 | from utils_trace import *
|
13 | 13 | from st_pages import hide_pages
|
| 14 | +import os |
| 15 | +import tkinter as tk |
| 16 | +from tkinter import filedialog |
| 17 | + |
| 18 | + |
| 19 | +def browse_file_folder(is_file, init_dir): |
| 20 | + root = tk.Tk() |
| 21 | + # root.withdraw() # Hide the main window |
| 22 | + if is_file == True: |
| 23 | + out_path = filedialog.askopenfilenames(initialdir = init_dir, multiple=0) |
| 24 | + else: |
| 25 | + out_path = filedialog.askdirectory(initialdir = init_dir) |
| 26 | + |
| 27 | + print('aaaaaa') |
| 28 | + print(out_path[0:5]) |
| 29 | + input() |
| 30 | + |
| 31 | + return out_path |
14 | 32 |
|
15 | 33 | #hide_pages(["Image Processing", "Data Analytics"])
|
16 | 34 |
|
@@ -202,80 +220,91 @@ def filter_dataframe(df: pd.DataFrame, pid) -> pd.DataFrame:
|
202 | 220 | # # Config page
|
203 | 221 | # st.set_page_config(page_title="DataFrame Demo", page_icon="📊", layout='wide')
|
204 | 222 |
|
205 |
| -# FIXME: Input data is hardcoded here for now |
206 |
| -fname = "../examples/test_input3/ROIS_tmp2.csv" |
207 |
| -df = pd.read_csv(fname) |
| 223 | +dir_root = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd()))) |
208 | 224 |
|
209 | 225 | # Page controls in side bar
|
210 | 226 | with st.sidebar:
|
211 |
| - |
212 | 227 | with st.container(border=True):
|
213 | 228 |
|
214 |
| - # Slider to set number of plots in a row |
215 |
| - st.session_state.plot_per_raw = st.slider('Plots per raw',1, 5, 3, key='a_per_page') |
| 229 | + # Input file name (user can enter either using the file browser or type full path) |
| 230 | + default_spare_name = '' |
| 231 | + fname_spare = st.sidebar.button("Select input file", on_click = browse_file_folder, key = 'fname_spare_btn', args=[True, dir_root]) |
| 232 | + if fname_spare == False: |
| 233 | + fname_spare = default_spare_name |
| 234 | + spare_csv = st.sidebar.text_input("Enter the name of the ROI csv file:", value = fname_spare, |
| 235 | + label_visibility="collapsed") |
216 | 236 |
|
217 |
| - with st.container(border=True): |
| 237 | +if os.path.exists(spare_csv): |
| 238 | + df = pd.read_csv(spare_csv) |
| 239 | + |
| 240 | + with st.sidebar: |
| 241 | + with st.container(border=True): |
| 242 | + |
| 243 | + # Slider to set number of plots in a row |
| 244 | + st.session_state.plot_per_raw = st.slider('Plots per raw',1, 5, 3, key='a_per_page') |
| 245 | + |
| 246 | + with st.container(border=True): |
| 247 | + |
| 248 | + st.write('Plot Settings') |
| 249 | + |
| 250 | + # Tabs for parameters |
| 251 | + ptabs = st.tabs([":lock:", ":large_orange_circle:", ":large_yellow_circle:", |
| 252 | + ":large_green_circle:"]) |
218 | 253 |
|
219 |
| - st.write('Plot Settings') |
220 |
| - |
221 |
| - # Tabs for parameters |
222 |
| - ptabs = st.tabs([":lock:", ":large_orange_circle:", ":large_yellow_circle:", |
223 |
| - ":large_green_circle:"]) |
224 |
| - |
225 |
| - # Tab 0: to set plotting parameters |
226 |
| - with ptabs[1]: |
227 |
| - # Default values for plot params |
228 |
| - st.session_state.default_hue_var = 'Sex' |
229 |
| - |
230 |
| - def_ind_x = 0 |
231 |
| - if st.session_state.default_x_var in df.columns: |
232 |
| - def_ind_x = df.columns.get_loc(st.session_state.default_x_var) |
233 |
| - |
234 |
| - def_ind_y = 0 |
235 |
| - if st.session_state.default_y_var in df.columns: |
236 |
| - def_ind_y = df.columns.get_loc(st.session_state.default_y_var) |
237 |
| - |
238 |
| - def_ind_hue = 0 |
239 |
| - if st.session_state.default_hue_var in df.columns: |
240 |
| - def_ind_hue = df.columns.get_loc(st.session_state.default_hue_var) |
241 |
| - |
242 |
| - st.session_state.default_x_var = st.selectbox("Default X Var", df.columns, key=f"x_var_init", |
243 |
| - index = def_ind_x) |
244 |
| - st.session_state.default_y_var = st.selectbox("Default Y Var", df.columns, key=f"y_var_init", |
245 |
| - index = def_ind_y) |
246 |
| - st.session_state.default_hue_var = st.selectbox("Default Hue Var", df.columns, key=f"hue_var_init", |
247 |
| - index = def_ind_hue) |
248 |
| - trend_index = st.session_state.trend_types.index(st.session_state.default_trend_type) |
249 |
| - st.session_state.default_trend_type = st.selectbox("Default Trend Line", st.session_state.trend_types, |
250 |
| - key=f"trend_type_init", index = trend_index) |
251 |
| - |
252 |
| - # Button to add a new plot |
253 |
| - if st.button("Add plot"): |
| 254 | + # Tab 0: to set plotting parameters |
| 255 | + with ptabs[1]: |
| 256 | + # Default values for plot params |
| 257 | + st.session_state.default_hue_var = 'Sex' |
| 258 | + |
| 259 | + def_ind_x = 0 |
| 260 | + if st.session_state.default_x_var in df.columns: |
| 261 | + def_ind_x = df.columns.get_loc(st.session_state.default_x_var) |
| 262 | + |
| 263 | + def_ind_y = 0 |
| 264 | + if st.session_state.default_y_var in df.columns: |
| 265 | + def_ind_y = df.columns.get_loc(st.session_state.default_y_var) |
| 266 | + |
| 267 | + def_ind_hue = 0 |
| 268 | + if st.session_state.default_hue_var in df.columns: |
| 269 | + def_ind_hue = df.columns.get_loc(st.session_state.default_hue_var) |
| 270 | + |
| 271 | + st.session_state.default_x_var = st.selectbox("Default X Var", df.columns, key=f"x_var_init", |
| 272 | + index = def_ind_x) |
| 273 | + st.session_state.default_y_var = st.selectbox("Default Y Var", df.columns, key=f"y_var_init", |
| 274 | + index = def_ind_y) |
| 275 | + st.session_state.default_hue_var = st.selectbox("Default Hue Var", df.columns, key=f"hue_var_init", |
| 276 | + index = def_ind_hue) |
| 277 | + trend_index = st.session_state.trend_types.index(st.session_state.default_trend_type) |
| 278 | + st.session_state.default_trend_type = st.selectbox("Default Trend Line", st.session_state.trend_types, |
| 279 | + key=f"trend_type_init", index = trend_index) |
| 280 | + |
| 281 | + # Button to add a new plot |
| 282 | + if st.button("Add plot"): |
| 283 | + add_plot() |
| 284 | + |
| 285 | + # Add a single plot (initial page includes one plot) |
| 286 | + if st.session_state.plots.shape[0] == 0: |
254 | 287 | add_plot()
|
255 | 288 |
|
256 |
| -# Add a single plot (initial page includes one plot) |
257 |
| -if st.session_state.plots.shape[0] == 0: |
258 |
| - add_plot() |
259 |
| - |
260 |
| -# Read plot ids |
261 |
| -df_p = st.session_state.plots |
262 |
| -p_index = df_p.PID.tolist() |
263 |
| -plot_per_raw = st.session_state.plot_per_raw |
264 |
| - |
265 |
| -# Render plots |
266 |
| -# - iterates over plots; |
267 |
| -# - for every "plot_per_raw" plots, creates a new columns block, resets column index, and displays the plot |
268 |
| -for i in range(0, len(p_index)): |
269 |
| - column_no = i % plot_per_raw |
270 |
| - if column_no == 0: |
271 |
| - blocks = st.columns(plot_per_raw) |
272 |
| - with blocks[column_no]: |
273 |
| - display_plot(p_index[i]) |
274 |
| - |
275 |
| - |
276 |
| -# FIXME: this is for debugging for now; will be removed |
277 |
| -# with st.expander('Saved DataFrames'): |
278 |
| -with st.container(): |
279 |
| - st.session_state.plots |
| 289 | + # Read plot ids |
| 290 | + df_p = st.session_state.plots |
| 291 | + p_index = df_p.PID.tolist() |
| 292 | + plot_per_raw = st.session_state.plot_per_raw |
| 293 | + |
| 294 | + # Render plots |
| 295 | + # - iterates over plots; |
| 296 | + # - for every "plot_per_raw" plots, creates a new columns block, resets column index, and displays the plot |
| 297 | + for i in range(0, len(p_index)): |
| 298 | + column_no = i % plot_per_raw |
| 299 | + if column_no == 0: |
| 300 | + blocks = st.columns(plot_per_raw) |
| 301 | + with blocks[column_no]: |
| 302 | + display_plot(p_index[i]) |
| 303 | + |
| 304 | + |
| 305 | + # FIXME: this is for debugging for now; will be removed |
| 306 | + # with st.expander('Saved DataFrames'): |
| 307 | + with st.container(): |
| 308 | + st.session_state.plots |
280 | 309 |
|
281 | 310 |
|
0 commit comments