diff --git a/src/viewer/pages/plot_sMRI_vars_study.py b/src/viewer/pages/plot_sMRI_vars_study.py index adffbdd..3c321bb 100644 --- a/src/viewer/pages/plot_sMRI_vars_study.py +++ b/src/viewer/pages/plot_sMRI_vars_study.py @@ -88,6 +88,8 @@ def panel_incsv() -> None: st.session_state.paths["file_search_dir"], ) + print(f'aaaa {st.session_state.is_updated["csv_plot"]}') + if os.path.exists(st.session_state.paths["csv_plot"]): p_plot = st.session_state.paths["csv_plot"] st.success(f"Data is ready ({p_plot})", icon=":material/thumb_up:") @@ -103,6 +105,7 @@ def panel_incsv() -> None: st.session_state.is_updated["csv_plot"] = False # Show input data + if os.path.exists(st.session_state.paths["csv_plot"]): with st.expander('Show input data', expanded=False): st.dataframe(st.session_state.plot_var["df_data"]) @@ -188,6 +191,10 @@ def panel_select() -> None: df = st.session_state.plot_var["df_data"] + if 'MRID' not in df.columns: + st.warning('The data file does not contain the required "MRID" column. The operation cannot proceed.') + return + with open(st.session_state.dict_categories, "r") as f: dict_categories = json.load(f) @@ -247,11 +254,13 @@ def panel_select() -> None: sel_vars = sel_vars + vars_cent st.session_state.plot_sel_vars = sel_vars - print(f'sss {vars_cent} nnnn {sel_vars}') - df = df[st.session_state.plot_sel_vars] st.session_state.plot_var["df_data"] = df + with st.expander('Show selected data', expanded=False): + st.dataframe(st.session_state.plot_var["df_data"]) + + col1, col2 = st.columns([0.5, 0.1]) with col2: if st.button("Revert to initial data", use_container_width=True): diff --git a/src/viewer/utils/utils_st.py b/src/viewer/utils/utils_st.py index c9400a7..c7d7a59 100644 --- a/src/viewer/utils/utils_st.py +++ b/src/viewer/utils/utils_st.py @@ -268,7 +268,6 @@ def util_panel_workingdir(app_type: str) -> None: utilses.update_default_paths() utilses.reset_flags() - def copy_uploaded_to_dir() -> None: # Copies files to local storage if len(st.session_state["uploaded_input"]) > 0: @@ -312,11 +311,6 @@ def util_upload_file( Upload user data to target folder Input data is a single file """ - # Set target path - if not flag_disabled: - if not os.path.exists(os.path.dirname(out_file)): - os.makedirs(os.path.dirname(out_file)) - # Upload input in_file = st.file_uploader( title_txt, @@ -325,14 +319,18 @@ def util_upload_file( disabled=flag_disabled, label_visibility=label_visibility, ) + if in_file is None: + return False - # Copy to target - if not os.path.exists(out_file): - utilio.copy_uploaded_file(in_file, out_file) - return True - - return False - + # Create parent dir of out file + if not os.path.exists(os.path.dirname(out_file)): + os.makedirs(os.path.dirname(out_file)) + # Remove existing output file + if os.path.exists(out_file): + os.remove(out_file) + # Copy selected input file to destination + utilio.copy_uploaded_file(in_file, out_file) + return True def util_select_folder( key_selector: str,