Error when uploading csv file with file input widget

Solution for Error when uploading csv file with file input widget
is Given Below:

original
When I try to upload my csv file I recieve an error stating that “input string 7 is invalid in this locale”. I have attempted to use encoding= “UTF-8″ and encoding=”UTF-16LE”. I used UTF-16LE because I researched that this is the encoding used for csv files. However, I am still running into the error message. I am unsure how to check the encoding of the csv file.

Update:
I am able to upload my file when I use fileEncoding = “UTF-8”. However, the app is not recognizing the rows and columns.

enter image description here

library(shiny)

ui <- fluidPage(
  
  navbarPage("Dashboard",
             
             tabPanel(title = "Model",
                      sidebarLayout(
                        sidebarPanel(
                          
                          fileInput("file1", "Choose .csv file", #add red asterisks to make this mandatory
                                    accept = c(
                                      "text/csv",
                                      "text/comma-separated-values,text/plain",
                                      ".csv"),
                          ),    
                          
                        ),
                        
                        mainPanel(
                          tabsetPanel(
                            tabPanel("Data",
                                     tableOutput("tableOne"))
                            
                          )
                        )    
                      )    
             )
  )
)

server <- function(input,output){
  
  data <- reactive({
    req(input$file1)
    file1 <- input$file1
    if(is.null(file1)){return()}
    read.table(file=file1$datapath, fileEncoding = "UTF-8")
    
  })
  
 
  
  output$tableOne <- renderTable({
    req(input$file1)
    if(is.null(data())){return ()}
    data()
  })
  
  #output$data <- renderTable(output$tableOne)
  
}


shinyApp(ui,server)

The issue was with the delimiter getting changed from space to , while saving the data. So, the OP’s code

 read.table(file=file1$datapath, fileEncoding = "UTF-8")

which was looking for the default space in sep didn’t find one.

We could change that line to

read.csv(file = file1$datapath, fileEncoding = "UTF-8")

or use read.table with an extra sep

read.table(file=file1$datapath, fileEncoding = "UTF-8", sep=",")