【问题标题】:Issues while displaying the dataset and unloading previous operations显示数据集和卸载以前的操作时出现问题
【发布时间】:2020-04-01 18:54:13
【问题描述】:

我在应用程序中遇到的问题很少。这是我 add 和加载 csv 文件的代码。但是有一些问题,我也需要一些东西。请求任何人帮助我

问题: 1)我无法加载第二个文件。不知道为什么? 2) 我也添加了删除按钮,因此一旦单击Remove 按钮,相应的文件就会被卸载。 3)我们可以创建另一个输出,当加载新文件时,它应该显示前15行head(df, n = 6)

---
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}
actionButton("add", "Add UI",width = 100)

observeEvent(input$add, {
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = fileInput("file1", "Choose CSV File", accept = c( "text/csv", "text/comma-separated-values,text/plain", ".csv"))
      ,multiple = FALSE
    )
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = actionButton("V","Remove",width = 100))
  })
observeEvent(input$V,{
     removeUI(selector = '#file1')
   }) 
```

【问题讨论】:

  • 这可能有助于removeUI stackoverflow.com/questions/42548083/…
  • 我试过但没有工作。我已经编辑了我的问题。此外,还有其他问题。像 1) 我无法加载第二个文件。不知道为什么? 2)我们可以创建另一个输出,当加载新文件时,它应该显示前 15 行 head(df, n = 6)。请帮忙

标签: jquery r shiny


【解决方案1】:

这里有一个不同的设计,我希望它有所帮助

---
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}
actionButton("add", "Add UI",width = 100)
observeEvent(input$add, {
  remove_id <- paste0("remove_", input$add)
  insertUI(
    selector = "#add",
    where = "afterEnd",
    ui = tags$div(fileInput(paste0("file",input$add), paste0("Choose CSV File", input$add), accept = c( "text/csv", "text/comma-separated-values,text/plain", ".csv")),
                  actionButton(remove_id, paste0("Remove",input$add), width = 100), id=remove_id), multiple = FALSE)

observeEvent(input[[remove_id]],{
  removeUI(selector = paste0("#",remove_id), immediate = TRUE, multiple = TRUE)
})
})

```

【讨论】:

  • 嗨,苏利曼。非常感谢。其实我也试过这个。但是如果你仔细观察,当你点击 Add two/twice 等等时,你无法加载 2 个数据集。那里有一些我无法解决的错误。请尝试一次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
  • 2011-11-21
  • 1970-01-01
  • 2011-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多