R shiny remove UI keeps the label

你。 提交于 2021-02-19 07:34:10

问题


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 divs. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!