0

My goal is to upload two or more files where each file would have a different delimiter. The ui.R and server.R code below provides an example that works well when both files are read in and have the same delimiter.

However, if I read in file1, say as a .csv, and then read in file2 with a different delimiter, then once I change the delimiter, file1 is then affected and loses its structure.

The objective is to read in file1 with its intended delimiter and then subsequently read in file2 such that it has no impact on file1.

server.R File

    options(shiny.maxRequestSize = 9*1024^2)
    shinyServer(function(input, output) {

    output$contents1 <- renderTable({
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
    read.csv(inFile$datapath, header = input$header,
             sep = input$sep, quote = input$quote)
    })

    output$contents2 <- renderTable({
    inFile <- input$file2
    if (is.null(inFile))
      return(NULL)
    read.csv(inFile$datapath, header = input$header,
             sep = input$sep, quote = input$quote)
    })
    })

ui.R

shinyUI(fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
        sidebarPanel(
        fileInput('file1', 'Choose file 1 to upload',
        accept = c('text/csv','text/comma-separated-values',
        'text/tab-separated-values', 'text/plain',
        '.csv', '.tsv')
        ),
        fileInput('file2', 'Choose file 2 to upload',
        accept = c('text/csv','text/comma-separated-values',
        'text/tab-separated-values','text/plain',
        '.csv','.tsv')
        ),      
        tags$hr(),
        checkboxInput('header', 'Header', TRUE),
        radioButtons('sep', 'Separator',
        c(Comma=',',Semicolon=';',
        Tab='\t',Pipe='|'),
        ','),
        radioButtons('quote', 'Quote',
        c(None='','Double Quote'='"',
        'Single Quote'="'"),
        '"'),
        tags$hr()
        ),
        mainPanel(
        tableOutput('contents1'),
        tableOutput('contents2')
        )
        )
        ))
dhc
  • 625
  • 1
  • 6
  • 14

1 Answers1

0

I realize this is not a direct solution to work with both at once, but can you create a second pair of radio buttons to associate with the second file you are inputting?

This is what i mean.

Shiny

What would be nice if you could somehow put the 2nd separator adjacent to separator, and 2nd quote adjacent to quote. I am not great at how to do the layout of an app, but the link below may help out with this issue.

shiny 4 small textInput boxes side-by-side

Try to see if you can toy around with this by replacing the textInput statements with radiobuttons.

I've had issues with shiny accepting one input into multiple inputs or objects in the ui before, and this is a way to bypass it. I am unsure why shiny has this issue. That's a question for someone more qualified than myself.

Community
  • 1
  • 1
InfiniteFlash
  • 1,038
  • 1
  • 10
  • 22
  • Thank you. I was able to create a second set of radio buttons to apply only to the separate data file. It does indeed work, although aesthetically it crowds the page. Functionality is my primary objective, so I can work from here. But, I am curious if there is a solution that is more elegant w.r.t. being visually pleasing – dhc Feb 12 '16 at 11:53