The insetUI - removeUI dilemma: Removing labels with no IDs

198 views
Skip to first unread message

Cornelis Janse de Jager

unread,
Aug 11, 2017, 1:53:48 AM8/11/17
to Shiny - Web Framework for R
I have been stuck on this problem for quite some time, basically when using insertUI to create a new inputText, it also creates a new label. The label itself doesn't have an ID associated with it, so when we call removeUI, only the input text box gets deleted but not the label, leaving annoying snippets of text all over your program!!!

Here is the code I used:

insertUI(
        selector = "#evControls",
        where = "afterEnd",
        ui = textInput(inputId = el_id, label = el_text, width = "100%", placeholder = "Example: -EV0 -EV24 -kgmp"),
        immediate = FALSE
      )
...
removeUI(
        selector = paste0("#", el_id),
        multiple = TRUE,
        immediate = TRUE,
        session
      )


In browser this is the code created:

<div class="form-group shiny-input-container" style="width: 100%;">
  <label for="LabFe">Fe</label>
  <input id="LabFe" type="text" class="form-control shiny-bound-input" value="" placeholder="Example: -EV0 -EV24 -kgmp">
</div>

 And after it gets removed:

<div class="form-group shiny-input-container" style="width: 100%;">
  <label for="LabFe">Fe</label>
</div>

Has anybody else experienced this? Is there a work around?

peter.sm...@gmail.com

unread,
Aug 18, 2017, 12:15:09 PM8/18/17
to Shiny - Web Framework for R
Hello,
Is it ok to remove the whole container for the input? 
if so then use the following removeUI, the jquery selector uses . prefix to specify class selector and :has() that checks if there is any child inside with given filter therefore:
.shiny-input-container selects all elements with class "shiny-input-container"
and then :has(#%s) filters abovementioned for those that have at least one child with id=#+el_id

removeUI(
               selector
= sprintf('.shiny-input-container:has(#%s)',el_id),
Reply all
Reply to author
Forward
0 new messages