posit-dev / posit-dev/py-shiny
ui.remove_ui() fails for some inputs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 135
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 21
Description
Hey shiny team,
It may be user error, but I ran into an issue when trying to remove an input_slider() with ui.remove_ui().
When I try to use ui.remove_ui() on an input_slider() it doesn't remove the slider, but the same code works with input_radio_buttons() and input_action_button() (I modified the dynamic UI example on shinylive).
ui.remove_ui() sort of works with input_numeric() , input_select(), input_text() and input_checkbox() but leaves the label/title when ui.remove_ui() is called.
In the app below, you can see the different inputs that I tried to insert and remove.
App Code here:
from shiny import App, reactive, render, ui
# For plot rendering
import matplotlib.pyplot as plt
import numpy as np
app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.panel_sidebar(
ui.h2("Dynamic UI"),
ui.output_ui("ui"),
ui.input_action_button("btn", "Trigger insert/remove ui"),
),
ui.panel_main(
ui.output_text_verbatim("txt"),
ui.output_plot("plot"),
),
),
)
def server(input, output, session):
@reactive.Calc
def r():
return input.n() * 2
@output
@render.text
def txt():
return f"n*2 is {r()}, session id is {session.id}"
@output
@render.plot(alt="A histogram")
def plot():
np.random.seed(19680801)
x = 100 + 15 * np.random.randn(437)
fig, ax = plt.subplots()
ax.hist(x, input.n(), density=True)
return fig
@output(id="ui")
@render.ui
def _():
return ui.input_slider(
"N", "This slider is rendered via @render.ui", 0, 100, 20
)
@reactive.Effect
def _():
btn = input.btn()
if btn % 2 == 1:
ui.insert_ui(
# doesn't work
ui.input_slider("thanks", "CHOOSE", 1, 100, 10),
# works but leaves label/title
# ui.input_numeric("thanks", "CHOOSE", 10, min = 1, max = 100),
# ui.input_checkbox("thanks", "CHOOSE", False),
# ui.input_select("thanks", "CHOOSE", {"A": "a", "B": "b", "C": "c"}),
# ui.input_text("thanks", "CHOOSE", "Data summary"),
# works
# ui.input_action_button("thanks", "CHOOSE"),
# ui.input_radio_buttons("thanks", "CHOOSE", {"A": "A", "B": "B", "C": "C"}),
"body"
)
elif btn > 0:
ui.remove_ui("#thanks")
app = App(app_ui, server, debug=True)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Shiny app reproduction and compare ui.remove_ui() behavior for input_slider() with the other input types shown. Trace the ui.remove_ui() and input_slider() entry points; done means removing the slider also removes its label and title, without breaking the working input cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100