From f2ebe7750986420648764d351aac55105f3ee4f7 Mon Sep 17 00:00:00 2001 From: Nico Trummer Date: Sun, 10 Mar 2024 12:54:07 +0000 Subject: [PATCH] Fix column remove behaviour --- src/metadata.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/metadata.py b/src/metadata.py index 85d1bf4..b2ab077 100644 --- a/src/metadata.py +++ b/src/metadata.py @@ -37,12 +37,27 @@ def add_column(): _additional_columns.set(_additional_columns.get() + [column]) ui.update_text("column_name", value="") + @reactive.effect + def remove_column(): + original_columns = _additional_columns.get() + remaining_columns = [] + + for column in original_columns: + remove_accession = f"remove_column_{column}" + if input[remove_accession].get() > 0: + del input[remove_accession] + else: + remaining_columns.append(column) + + if len(remaining_columns) < len(original_columns): + _additional_columns.set(remaining_columns) + @reactive.effect def update_columns(): _all_columns.set(mandatory_columns + _additional_columns.get()) - def column_card(column: str): + def column_card(column: str, removable=False): adata = _adata.get() if adata is None: @@ -87,7 +102,7 @@ def column_card(column: str): interface, ui.card_footer( ui.input_action_button(f"remove_column_{column}", "Remove") - ), + ) if removable else ui.div(), style="min-width: 300px; max-width: 600px; flex: 1;" ) @@ -102,8 +117,10 @@ def column_cards(): style="min-width: 300px; max-width: 600px; flex: 1;" ) + additional_columns = _additional_columns.get() + return ui.div( - *[column_card(column) for column in _all_columns.get()], + *[column_card(column, column in additional_columns) for column in _all_columns.get()], add_card, style="display: flex; flex-wrap: wrap; gap: 10px" )