posit-dev / posit-dev/py-shiny

[Bug]: Inconsistent population of ui.input_selectize() by update_selectize()

Open
#1,990 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
Python
Stars
1.8k
Forks
135
Avg merge
2d 18h
Merged PRs (30d)
21

Description

Component

UI (ui.*)

Severity

P1 - High (major feature broken)

Shiny Version

1.2.1

Python Version

3.12.2

Minimal Reproducible Example
from shiny import App, render, ui

humu_tabs_mapped_to_gene_inputs = {"Mouse Gene Expression Box Plots" : [["humu_gex_box_gene", "Mouse"]],
                                   "Mouse Gene Expression Dotplots" : [["humu_gex_dot_gene", "Mouse"]],
                                   "HuMu Gene Expression Comparison" : [["humu_box_comp_human_genes", "Human"],["humu_box_comp_mu_genes", "Mouse"]],
}

app = app_ui = ui.page_fluid(
ui.nav_panel("Mouse Gene Expression Dotplots",
                    ui.layout_sidebar(
                        ui.sidebar(
                            ui.input_selectize("humu_gex_dot_gene", "Choose Genes to plot:", [], multiple=True),
                            ui.input_selectize("humu_gex_dot_groupby", "Group By:", hsh.categoricals_opts, selected="---"),
                            ui.input_selectize("humu_gex_dot_groups", "Subset Groupby Categories:", [], multiple=True),
                            ui.input_selectize("humu_gex_dot_splitby", "Split By:", ["---"] + hsh.categoricals_opts, selected="---"),
                            ui.input_selectize('humu_gex_dot_splits', "Subset Splitby Categories:", [], multiple=True),
                            ui.input_switch("humu_gex_dot_swap", "Swap Axes"),
                            ui.input_action_button("humu_gex_dot_run", "RUN"),
                            bg=panel_color
                        ),
                    ui.card(ui.output_plot("humu_plot_gex_dotplot"), min_height="750px", full_screen=True)
                    )       
                ),
)

def server(input, output, session):
@reactive.effect
    def populate_gene_selections():
        current_tab = input.humu_top_nav()
        if current_tab not in humu_tabs_visited:
            humu_tabs_visited.append(current_tab)
            if current_tab in humu_tabs_mapped_to_gene_inputs:
                for id, category in humu_tabs_mapped_to_gene_inputs[current_tab]:
                    if category == "Mouse":
                        ui.update_selectize(
                            id,
                            choices=hsh.genes,
                            selected=[],
                            server=True,
                        )
                    else:
                        ui.update_selectize(
                            id,
                            choices=qsh.genes,
                            selected=[],
                            server=True,
                        )
Behavior

I have multiple input_selectize dropdowns that take a large number of options. To avoid long startup times for the app I initialize them as empty at first and then when the user visits a tab, the input_selectize in that tab is filled in on the server side.

However, with my hosted shiny app on shinyproxy, often random input_selectizes fail to update or display options. This isn't strictly reproducible across sessions and sometimes when the app is reloaded the input_selectize() that was broken on during a previous session works and a new input_selectize doesn't work. This doesn't happen when I run my app locally but seems to be specific to shinyproxy, but not sure how to get around this.

Error Messages (if any)

Environment
OS: Ubuntu 22.02
Browser: Firefox, Chrome
Dependencies: Shiny proxy

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal reproducible example with the listed Python and Shiny setup, then compare behavior locally and behind ShinyProxy. Trace the ui.update_selectize calls as tabs are visited and determine why options are intermittently absent; done means every visited selectize consistently displays its server-populated choices in the affected deployment.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.