Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 无法删除以前插入的UI_R - Fatal编程技术网

R 无法删除以前插入的UI

R 无法删除以前插入的UI,r,R,在下面的应用程序中,我无法删除以前插入的UI。不知道为什么。有人能帮忙吗 --- title: "Untitled" runtime: shiny output: flexdashboard::flex_dashboard: orientation: columns vertical_layout: fill --- ```{r setup, include=FALSE} library(flexdashboard) library(rhandsontable) ```r

在下面的应用程序中,我无法删除以前插入的UI。不知道为什么。有人能帮忙吗

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(rhandsontable)
```r

Column {data-width=650}
-----------------------------------------------------------------------

### Insert and Remove UI

```{r}

actionButton("add", "Add UI")
actionButton("rmv", "Remove UI")
 observeEvent(input$add, {
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = textInput(paste0("txt", input$add),
                     "Insert some text"),multiple = FALSE
    )
  })
 observeEvent(input$rmv, {
    removeUI(
      selector = "div:has(< #txt)"
    )
  })
```

```
---
标题:“无标题”
运行时间:闪亮
输出:
flexdashboard::flex_仪表板:
方向:列
垂直布局:填充
---
```{r设置,include=FALSE}
库(flexdashboard)
图书馆(rhandsontable)
```r
列{数据宽度=650}
-----------------------------------------------------------------------
###插入和删除用户界面
```{r}
操作按钮(“添加”、“添加UI”)
操作按钮(“rmv”、“删除UI”)
ObserveeEvent(输入$add{
插入器(
选择器=“#添加”,
where=“afterEnd”,
ui=文本输入(粘贴0(“txt”,输入$add),
“插入一些文本”),多个=FALSE
)
})
observeEvent(输入$rmv{
移除(
选择器=“div:has(<#txt)”
)
})
```
```

我们可以使用
seq_len(input$add)
获取以前的ID,其中
input$add
是1,2,3,。。。etc,然后使用
paste0
sprintf

---
title: "Untitled"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(rhandsontable)
```

Column {data-width=650}
-----------------------------------------------------------------------

```{r}



  ### Insert and Remove UI

actionButton("add", "Add UI")
actionButton("rmv", "Remove UI")
observeEvent(input$add, {
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = textInput(paste0("txt", input$add),
                     sprintf("Insert some text for %i",input$add)),multiple = FALSE
    )
  })
observeEvent(input$rmv, {
    removeUI(
      #Remove the last UI
      #selector = sprintf("div:has(> #txt%i)",input$add),
      #Remove all previous UIs
      selector = sprintf("div:has(%s)",paste0('> #txt', seq_len(input$add), collapse = ",")),
      immediate = TRUE,
      multiple = TRUE
    )
  })
```
更新 每次用户单击“删除UI”时删除最后一个UI

插入和删除用户界面 操作按钮(“添加”、“添加UI”) 操作按钮(“rmv”、“删除UI”) 数据=反应值(tmp=0) ObserveeEvent(输入$add{
data$tmp谢谢。它几乎可以工作了。但是它只删除了最后一个操作。(对不起,我的错误)。如果我需要之前的所有操作,该怎么办?另外,它只删除文本框,标题保持原样。(未删除)@Suliman,当我将
textInput
替换为
fileInput
时,我有点怀疑,为什么删除UI不起作用。它应该可以正常工作?不幸的是,它们不一样try
fileInput(“file1”,“Choose CSV File”,accept=c(“text/CSV”,“text/逗号分隔值,text/plain”,“.CSV”))
文本输入(粘贴0(“txt”,1),sprintf(“为%i,1插入一些文本))
在R中。您好,这就是解决方案吗?我的意思是我应该替换上面的代码吗?不,
textInput
fileInput
它们有不同的HTML结构,当您在R控制台中打印它们时可以看到。也许您应该发布一个新问题,并添加
闪亮的
jQuery
,因为tagsI已经在这里添加了这个问题
### Insert and Remove UI

actionButton("add", "Add UI")
actionButton("rmv", "Remove UI")
data = reactiveValues(tmp=0)
observeEvent(input$add, {
    data$tmp <- c(data$tmp,input$add)

    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = textInput(paste0("txt", input$add),
                     sprintf("Insert some text for %i",input$add)),multiple = FALSE
    )
  })

observeEvent(input$rmv, {
    rm <- tail(data$tmp, 1)
    data$tmp <- setdiff(data$tmp, rm)

    removeUI(
      #Remove the last UI
      #selector = sprintf("div:has(> #txt%i)",input$add),
      #Remove all previous UIs
      selector = sprintf("div:has(%s)",paste0('> #txt', rm, collapse = ",")),
      immediate = TRUE,
      multiple = TRUE
    )
  })