The app is asking the user to input predictor & dependent variables. For that I am using renderUI & uiOutput functions in server.R & ui.R files respectively. I am storing these inputs in predvar & depvar variables. Then i am using these variables in my reactive part of the code. This is where i think the problem of connection is between reactive code & user input variables. I have tried using caret::creatdatapartition instead of just createdatapartition. server.R code
model <- reactive ({
prop = input$prop
predictor = input$predvar
dependent = input$depvar
if(length(predictor)==0){return("Select atleast one predictor")}
if(input$ex==TRUE){data <- datasets::iris}
else{file1 <- input$file
data = read.table(file = file1$datapath,sep =",",header = TRUE)
data = as.data.frame(data)}
set.seed(69)
inTrain <- createDataPartition(y=data$dependent,p=prop,list = FALSE) ## this line throws error
train <- data[inTrain,]
train <- train %>% select(predictor,dependent)
train(dependent~.,data=data,method = "rpart")
})
output$model <- renderPrint({
model()
)}
output$dependent <- renderUI({
if(input$ex==TRUE){
data = datasets::iris
dependents <- select_if(data,is.factor)
selectInput("depvar","Select the dependent variable",choices = colnames(dependents))
}
else{
file1 <- input$file
data = read.table(file = file1$datapath,sep =",",header = TRUE)
dependents <- select_if(data,is.factor)
selectInput("depvar","Select the dependent variable",choices = colnames(dependents))
}
})
output$predictor <- renderUI({
if(input$ex==TRUE){
data = datasets::iris
dependents <- select_if(data,is.numeric)
checkboxGroupInput("predvar","Select the predictor variables",choices = colnames(dependents))
}
else{
file1 <- input$file
data = read.table(file = file1$datapath,sep =",",header = TRUE)
dependents <- select_if(data,is.numeric)
checkboxGroupInput("predvar","Select the predictor variables",choices = colnames(dependents))
}
})
concerning ui.R code
checkboxInput("ex","Uncheck for using your own file",value = TRUE),
fileInput("file", "Upload the *.csv file with headers"),
uiOutput("dependent"),
uiOutput("predictor"),
sliderInput("prop",
"Enter the training data ratio",
min = .5,
max = 1,
value = .6,step = .05)
)