问题
I am calling shiny removeUi() for an textInput, however, only the input section gets removed and not the label. See code and image below:
clearElements <- function (dat) {
observe({
for (el in dat) {
id <- strsplit(el,substring(el, nchar(el)-8, nchar(el)))[[1]]
print(id)
removeElement(id)
}
})
}
removeElement <- function (el_id) {
removeUI(
selector = paste0("#", el_id),
multiple = TRUE,
immediate = TRUE,
session
)
}
Here is the visual result:
回答1:
The accepted answer does not work.
You need to remove the entire .shiny-input-container like below
removeUI(
selector = sprintf('.shiny-input-container:has(#%s)',el_id)
)
回答2:
Several elements are wrapped in div
s. Try this instead:
removeElement <- function (el_id) {
removeUI(
selector = paste0("div:has(> #", el_id, ")")
)
}
来源:https://stackoverflow.com/questions/45627257/r-shiny-remove-ui-keeps-the-label