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')
)
)
))