Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select/Selectize ui.remove_ui does not remove label #1634

Open
IainNBSmith opened this issue Aug 23, 2024 · 2 comments
Open

Select/Selectize ui.remove_ui does not remove label #1634

IainNBSmith opened this issue Aug 23, 2024 · 2 comments

Comments

@IainNBSmith
Copy link

Lines 212-239 _input_select.py

return div(
shiny_input_label(resolved_id, label),
div(
tags.select(
*choices_tags,
{"class": "shiny-input-select"},
class_=None if selectize else "form-select",
id=resolved_id,
multiple=multiple,
size=size,
),
(
TagList(
tags.script(
dumps(opts),
type="application/json",
data_for=resolved_id,
data_eval=dumps(extract_js_keys(opts)),
),

selectize_deps(),
)
if selectize
else None
),
),
class_="form-group shiny-input-container",
style=css(width=width),
)

Main Issue

In bold the tag with the id for the selective element is a div that does not contain the label. So calling remove_ui('div:has(> #id)') will leave a stray label behind. The fix should just be moving the **TagList into the parent div.

@gadenbuie
Copy link
Collaborator

I can see that it'd be helpful in this case if the ID of the select input (or an attribute reflecting the ID of the select input) were higher up in the DOM structure.

Fortunately, for your use case, you can wrap the select element that you know you'll want to remove in a ui.div() with it's own ID that you can use in ui.remove().

Here's an example (also on shinylive):

from shiny.express import input, ui
from shiny import reactive

with ui.div(id="thing-select"):
    ui.input_selectize("thing", "Thing", choices=["a", "b", "c"])

ui.input_action_button("remove_thing", "Remove Selectize")


@reactive.effect
@reactive.event(input.remove_thing)
def _():
    ui.remove_ui("#thing-select")

@IainNBSmith
Copy link
Author

I'm using regular shiny not express. I have tried that before, it's in a longer piece of code that adds and removes named elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants