I want to have a feature in my shiny app that when someone uploads a file which is not in .csv format they recieve a warning and when they do upload in .csv format it prints the table. here is my UI code
shinyUI(
tabPanel("File Upload",
h4("File Upload"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV file to upload',
accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
)
),
mainPanel(
tableOutput('upload'),
h1(textOutput("warning1"))
)
)
)
)
and my Server code
shinyServer(function(input, output) {
output$upload <- renderTable({
#assign uploaded file to a variable
File <- input$file1
#catches null exception
if (is.null(File))
return(NULL)
read.csv(File$datapath)
})
output$warning1 <- renderPrint({
upload<- input$file1
if (is.null(upload))
return(NULL)
if (upload$type != c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
)
return ("Wrong File Format try again!")
})
}