How do I convert an uploaded CSV file into a data frame?

I have created a file upload section that uploads and reads CSV files as a table:

ui <- fluidPage(

titlePanel("Upload Transaction Data Set"),

 sidebarLayout(

    sidebarPanel(

  fileInput("file1", "Choose CSV File",
            multiple = FALSE,
            accept = c("text/csv",
                     "text/comma-separated-values,text/plain",
                     ".csv")),
  tags$hr(),

  checkboxInput("header", "Header", TRUE),

  radioButtons("sep", "Separator",
               choices = c(Tab = "\t"),
               selected = "\t"),

  radioButtons("quote", "Quote",
               choices = c(None = "",
                           "Double Quote" = '"',
                           "Single Quote" = "'"),
               selected = '"'),

  tags$hr(),

   radioButtons("disp", "Display",
               choices = c(Head = "head",
                           All = "all"),
               selected = "head")

),

mainPanel(

  tableOutput("contents")
       )
)

I have also created linear regression models that takes input from a data set:

thedata <- readxl::read_xlsx("data/transactionDataAlteredXLSX.xlsx")

set.seed(2)
library(caTools)
split <- sample.split(thedata, SplitRatio=0.7)

train <- subset(thedata, split=TRUE)
Actual <- subset(thedata, split=FALSE)


# Create the model
Model <- lm(Class ~.,data=train)
#Prediction
Prediction <- predict(Model, Actual)

#Comparing predicted vs actual model
plot(Actual$Class,type = "l",lty= 1.8,col = "red")
lines(Prediction, type = "l", col = "blue")
plot(Prediction,type = "l",lty= 1.8,col = "blue")
#Finding Accuracy

shinyApp(ui, server)

How do I make the linear regression models form the output of the file upload, and not from the dataset 'thedata'? I have suspicions that I need to convert the uploaded file to a data frame, and then use it as an object for the linear regression.

Thanks.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.