Я создал раздел загрузки файлов, который загружает и читает файлы CSV в виде таблицы:
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")
)
)
Я также создал модели линейной регрессии, которые получают данные из набора данных:
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)
Как сделать так, чтобы модели линейной регрессии формировали результат загрузки файла, а не из набора данных 'thedata'?
Спасибо.
Edit:
Преобразовал файл во фрейм данных, как предложено в коде сервера, затем я изменил «thedata» на «df» в коде регрессии, но теперь я получаю ошибку «unique () относится только к фрейму данных векторов», любые идеи :
server <- function(input, output) {
output$contents <- renderTable({
req(input$file1)
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
})
}