From f3c2ff789133fa63cfb9299b6b033eece3a0574c Mon Sep 17 00:00:00 2001 From: Boqiang Date: Tue, 15 Sep 2026 12:30:22 -0400 Subject: [PATCH 1/3] refactor(features): extract UI composition --- ui/features_ui.py | 129 +++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/ui/features_ui.py b/ui/features_ui.py index 0a70558..1911e89 100644 --- a/ui/features_ui.py +++ b/ui/features_ui.py @@ -8,70 +8,71 @@ def features_ui(): "Features", ui.card( {"style": "width:100%;"}, - ui.column( - 12, - ui.row( - ui.column( - 2, - ui.input_select( - "h1_feat", - "Select a Feature", - choices=[] - ), - ui.input_select( - "h1_layer", - "Select a Table", - choices=[], - selected=["Original"] - ), - ui.input_checkbox( - "h1_group_by_check", - "Group By", - value=False - ), - ui.input_checkbox( - "h1_log_x", - "Log X-axis", - value=False - ), - ui.input_checkbox( - "h1_log_y", - "Log Y-axis", - value=False - ), - ui.div(id="main-h1_dropdown"), - ui.div(id="main-h1_check"), - ui.div(id="main-h1_together_drop"), - accessible_slider( - "feat_slider", - "Rotate X-axis Labels (degrees)", - min_val=0, - max_val=90, - value=0, - step=1 - ), - ui.input_action_button( - "go_h1", - "Render Plot", - class_="btn-success" - ), - ui.div( - {"style": "padding-top: 20px;"}, - ui.output_ui("download_histogram1_button_ui") - ), - ), - ui.column( - 10, - ui.div( - {"style": "padding-bottom: 100px;"}, - ui.output_image( - "spac_Histogram_1", - width="100%", - height="60vh" - ) - ) - ) - ) + ui.row( + ui.column(3, _controls_panel()), + ui.column(9, _plot_panel()) ) ) ) + + +def _controls_panel(): + return ui.div( + ui.input_select( + "h1_feat", + "Select a Feature", + choices=[] + ), + ui.input_select( + "h1_layer", + "Select a Table", + choices=[], + selected=["Original"] + ), + ui.input_checkbox( + "h1_group_by_check", + "Group By", + value=False + ), + ui.input_checkbox( + "h1_log_x", + "Log X-axis", + value=False + ), + ui.input_checkbox( + "h1_log_y", + "Log Y-axis", + value=False + ), + ui.div(id="main-h1_dropdown"), + ui.div(id="main-h1_check"), + ui.div(id="main-h1_together_drop"), + accessible_slider( + "feat_slider", + "Rotate X-axis Labels (degrees)", + min_val=0, + max_val=90, + value=0, + step=1 + ), + ui.input_action_button( + "go_h1", + "Render Plot", + class_="btn-success" + ), + ui.div( + {"style": "padding-top: 20px;"}, + ui.output_ui("download_histogram1_button_ui") + ) + ) + + +def _plot_panel(): + return ui.div( + {"style": "padding-bottom: 100px;"}, + ui.output_image( + "spac_Histogram_1", + width="100%", + height="60vh" + ) + ) From 1bf4bc5d043dac9e671e1b9a69165ab9ebe37639 Mon Sep 17 00:00:00 2001 From: Boqiang Date: Tue, 15 Sep 2026 12:54:13 -0400 Subject: [PATCH 2/3] refactor(features_ui): organize control sections - Group existing inputs into core, plot, and figure configuration sections. - Add a local disclosure helper while preserving input IDs, dynamic insertion targets, defaults, and server behavior. - Make the primary render action span the controls panel. --- ui/features_ui.py | 89 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/ui/features_ui.py b/ui/features_ui.py index 1911e89..fefcbc0 100644 --- a/ui/features_ui.py +++ b/ui/features_ui.py @@ -18,6 +18,10 @@ def features_ui(): def _controls_panel(): return ui.div( + {"class": "controls-panel"}, + + # === SECTION 1: Core Parameters (always visible) === + ui.h4("Core Parameters"), ui.input_select( "h1_feat", "Select a Feature", @@ -29,36 +33,60 @@ def _controls_panel(): choices=[], selected=["Original"] ), - ui.input_checkbox( - "h1_group_by_check", - "Group By", - value=False - ), - ui.input_checkbox( - "h1_log_x", - "Log X-axis", - value=False - ), - ui.input_checkbox( - "h1_log_y", - "Log Y-axis", - value=False + + ui.hr(), + + # === SECTION 2: Plot Configuration (collapsible) === + _collapsible_section( + checkbox_id="h1_show_plot_config", + label="Show Plot Configuration", + content=[ + ui.input_checkbox( + "h1_group_by_check", + "Group By", + value=False + ), + ui.div(id="main-h1_dropdown"), + ui.div(id="main-h1_check"), + ui.div(id="main-h1_together_drop"), + ui.input_checkbox( + "h1_log_x", + "Log X-axis", + value=False + ), + ui.input_checkbox( + "h1_log_y", + "Log Y-axis", + value=False + ) + ] ), - ui.div(id="main-h1_dropdown"), - ui.div(id="main-h1_check"), - ui.div(id="main-h1_together_drop"), - accessible_slider( - "feat_slider", - "Rotate X-axis Labels (degrees)", - min_val=0, - max_val=90, - value=0, - step=1 + + ui.hr(), + + # === SECTION 3: Figure Configuration (collapsible) === + _collapsible_section( + checkbox_id="h1_show_figure_config", + label="Show Figure Configuration", + content=[ + accessible_slider( + "feat_slider", + "Rotate X-axis Labels (degrees)", + min_val=0, + max_val=90, + value=0, + step=1 + ) + ] ), + + ui.br(), + + # === Generate Button === ui.input_action_button( "go_h1", "Render Plot", - class_="btn-success" + class_="btn-success w-100" ), ui.div( {"style": "padding-top: 20px;"}, @@ -67,6 +95,17 @@ def _controls_panel(): ) +def _collapsible_section(checkbox_id, label, content): + """Create a collapsible section with checkbox toggle.""" + return ui.div( + ui.input_checkbox(checkbox_id, label, value=False), + ui.panel_conditional( + f"input.{checkbox_id}", + *content + ) + ) + + def _plot_panel(): return ui.div( {"style": "padding-bottom: 100px;"}, From efc514b06a4e460d3f1e220065cc1938329cde26 Mon Sep 17 00:00:00 2001 From: Boqiang Date: Tue, 15 Sep 2026 14:21:22 -0400 Subject: [PATCH 3/3] refactor(features): use static group controls - Declare Annotation, Plot Together, and Stack Type in nested conditional UI. - Update Features annotation choices through the central effect updater. - Remove dynamic insertion state and effects while preserving histogram behavior. --- server/effect_update_server.py | 2 +- server/features_server.py | 62 ---------------------------------- ui/features_ui.py | 25 ++++++++++++-- 3 files changed, 23 insertions(+), 66 deletions(-) diff --git a/server/effect_update_server.py b/server/effect_update_server.py index 7a1ac9e..89d761d 100644 --- a/server/effect_update_server.py +++ b/server/effect_update_server.py @@ -28,6 +28,7 @@ def update_select_input_anno(): new_choices = choices + ["No Annotation"] ui.update_select("bp_anno", choices=new_choices) ui.update_select("h2_anno", choices=choices) + ui.update_select("h1_anno", choices=choices) ui.update_select("hm1_anno", choices=choices) if choices is not None and len(choices) > 1: @@ -322,4 +323,3 @@ def restore_to_master(): # Clear the subset history since the data is restored subset_history.set("") - diff --git a/server/features_server.py b/server/features_server.py index e12e501..76673de 100644 --- a/server/features_server.py +++ b/server/features_server.py @@ -123,9 +123,6 @@ def spac_Histogram_1(): "alt": "Feature histogram", } - histogram_ui_initialized = reactive.Value(False) - - @render.download(filename="features_histogram_data.csv") def download_histogram1_df(): df = shared['df_histogram1'].get() @@ -135,7 +132,6 @@ def download_histogram1_df(): return csv_bytes, "text/csv" return None - @render.ui @reactive.event(input.go_h1, ignore_none=True) def download_histogram1_button_ui(): @@ -146,61 +142,3 @@ def download_histogram1_button_ui(): class_="btn-warning" ) return None - - - @reactive.effect - def histogram_reactivity(): - btn = input.h1_group_by_check() - ui_initialized = histogram_ui_initialized.get() - - if btn and not ui_initialized: - dropdown = ui.input_select( - "h1_anno", - "Select an Annotation", - choices=shared['obs_names'].get() - ) - ui.insert_ui( - ui.div({"id": "inserted-dropdown"}, dropdown), - selector="#main-h1_dropdown", - where="beforeEnd", - ) - - together_check = ui.input_checkbox( - "h1_together_check", - "Plot Together", - value=True - ) - ui.insert_ui( - ui.div({"id": "inserted-check"}, together_check), - selector="#main-h1_check", - where="beforeEnd", - ) - - histogram_ui_initialized.set(True) - - elif not btn and ui_initialized: - ui.remove_ui("#inserted-dropdown") - ui.remove_ui("#inserted-check") - ui.remove_ui("#inserted-dropdown_together") - histogram_ui_initialized.set(False) - - - @reactive.effect - @reactive.event(input.h1_together_check) - def update_stack_type_dropdown(): - if input.h1_together_check(): - dropdown_together = ui.input_select( - "h1_together_drop", - "Select Stack Type", - choices=['stack', 'layer', 'dodge', 'fill'], - selected='stack' - ) - ui.insert_ui( - ui.div( - {"id": "inserted-dropdown_together"}, - dropdown_together - ), - selector="#main-h1_together_drop", - where="beforeEnd",) - else: - ui.remove_ui("#inserted-dropdown_together") diff --git a/ui/features_ui.py b/ui/features_ui.py index fefcbc0..ca1e276 100644 --- a/ui/features_ui.py +++ b/ui/features_ui.py @@ -46,9 +46,28 @@ def _controls_panel(): "Group By", value=False ), - ui.div(id="main-h1_dropdown"), - ui.div(id="main-h1_check"), - ui.div(id="main-h1_together_drop"), + ui.panel_conditional( + "input.h1_group_by_check", + ui.input_select( + "h1_anno", + "Select an Annotation", + choices=[] + ), + ui.input_checkbox( + "h1_together_check", + "Plot Together", + value=True + ), + ui.panel_conditional( + "input.h1_together_check", + ui.input_select( + "h1_together_drop", + "Select Stack Type", + choices=["stack", "layer", "dodge", "fill"], + selected="stack" + ) + ) + ), ui.input_checkbox( "h1_log_x", "Log X-axis",