I have a method where I want to split my data depending on a variable.
My code looks like this:
split_data <- eventReactive(input$split_btn, {
req(input$variables)
set.seed(123)
createDataPartition(data()$Survived, p = input$split_percent, list=FALSE)
})
train_data <- reactive({
data()[split_data(), ]
})
test_data <- reactive ({
data()[-split_data(), ]
})
This works perfectly, I have a slider that chooses the % of the split and updates it whenever I move It.
The problem comes when I try to use a selectInput to choose between my variables instead of just putting "Survived" since I want ppl that use my app to choose it freely.
selectInput("variable", "Seleccione la variable target:",
choices = names(data())),
createDataPartition(data()$input$variable, p = input$split_percent, list=FALSE)
These don't work and I get this error:
Warning: Error in createDataPartition: y must have at least 2 data points
I tried using as.name() and .data[[]] around my input, but it does not work.
There is something I'm missing about using dynamically selected variables in other functions that require it since I had other problems previously