How to upload a folder of csv files to brilliant

I have a folder with CSV files, and I want to download and access them as a list of files in brilliant form. I tried the following code to upload files.

server: output$sourced <- renderDataTable({

        inFile <- input$file1

        if (is.null(inFile))
          return(NULL)

        df <- list.files(inFile$datapath)  #, header=input$header, sep=input$sep, quote=input$quote)

    }) 

ui.r:  fileInput("file1", "Choose CSV files from directory", multiple = "TRUE",
                accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),

Error loading folder:

invalid 'description' argument

For one file, it works fine if I use df <- read.csv(inFile$datapath)to download the file. But m cannot load the folder. Help evaluate.

+4
source share
1 answer

Assuming the CSV files have the same structure and you want to combine them, a minimal working example might be:

ui.R

library(shiny)

shinyUI(
  fluidPage(
    fileInput("file1",
              "Choose CSV files from directory",
              multiple = TRUE,
              accept=c('text/csv', 
                       'text/comma-separated-values,text/plain', 
                       '.csv')),
    dataTableOutput("sourced")
))

server.R

library(shiny)
library(dplyr)

shinyServer(function(input, output) {

  output$sourced <- renderDataTable({

    inFile <- input$file1
    if (is.null(inFile)) {
      return(NULL)
    } else {
      inFile %>%
        rowwise() %>%
        do({
          read.csv(.$datapath)
        })
    }
  }) 

})
+3
source

All Articles