Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.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
将上载的csv与r中的当前数据帧合并_R_Shiny - Fatal编程技术网

将上载的csv与r中的当前数据帧合并

将上载的csv与r中的当前数据帧合并,r,shiny,R,Shiny,我正在处理的例子是虹膜数据。如果当前数据包含iris[1:15,],如何上载包含更多iris数据的.csv文件,并单击按钮将上载的数据与当前数据合并,并将所有内容保存在一个数据帧中 以下是我迄今为止根据我所读到的内容得出的结论。我能够创建fileInput和action按钮,但我认为我的问题在于被动按钮。我不知道如何正确地使用它来实现我所需要的 library(shiny) library(DT) data1<-data.frame(iris[1:15,]) ui <- flui

我正在处理的例子是虹膜数据。如果当前数据包含
iris[1:15,]
,如何上载包含更多iris数据的.csv文件,并单击按钮将上载的数据与当前数据合并,并将所有内容保存在一个数据帧中

以下是我迄今为止根据我所读到的内容得出的结论。我能够创建fileInput和action按钮,但我认为我的问题在于被动按钮。我不知道如何正确地使用它来实现我所需要的

library(shiny)
library(DT)

data1<-data.frame(iris[1:15,])

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      numericInput('num','Number of rows',value=10,min=0),

    actionButton("update", "Combine Data")),


    mainPanel(
      tableOutput("table")
    )
  )
)

server <- function(input, output) {
   output$table <- renderTable({
     head(data1,n=input$num)
   })


x<-reactive({
  req(input$file1)
  df_uploaded <- read.csv(input$file1$datapath,
                 header = input$header,
                 sep = input$sep,
                 quote = input$quote,
                 stringsAsFactors = FALSE)
  data2<-data.frame(df_uploaded)
  return(data2)
})

merged_data<-eventReactive(input$update,{
  datam<-rbind.data.frame(data1,x())
  return(datam)
})

# output$table <- renderTable({
#              head(merged_data(),n=input$num)})
}  


shinyApp(ui, server)
库(闪亮)
图书馆(DT)

数据1主要问题是
read.csv
接收到无效参数,即
header、sep、quote
NULL
,因为用户界面中没有
input$header、input$sep、input$quote

library(shiny)
library(DT)

data1<-data.frame(iris[1:15,])

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      numericInput('num','Number of rows',value=10,min=0),

      actionButton("update", "Combine Data")),


    mainPanel(
      tableOutput("table")
    )
  )
)

server <- function(input, output) {
  # output$table <- renderTable({
  #   head(data1,n=input$num)
  # })

  x<-reactive({
    req(input$file1)
    df_uploaded <- read.csv(input$file1$datapath,
                            #you don't have these variables in the UI, so they will raise an error
                            #header = input$header,
                            #sep = input$sep,
                            #quote = input$quote,
                            stringsAsFactors = FALSE)
    #No need data2 and return(data2) as read.csv returns data.frame by default
    #data2<-data.frame(df_uploaded)
    #return(data2)
  })

  merged_data<-eventReactive(input$update,{
    datam<-rbind.data.frame(data1, x())
    return(datam)
  })

  output$table <- renderTable({
               head(merged_data(), n=input$num)})
}  


shinyApp(ui, server)
库(闪亮)
图书馆(DT)
数据1