'Select Column in R Shiny and use it as a response in knn?

I try to create an app in which I could select an Error variable in the UI part of the shiny with selectInput and use this selected column as a response variable of means clustering and use the rest of the data as predictors. My server part is as follows:

server <- function(input, output){

source("model.R")
source("modelClust.R")
source("modelBayes.R")
source("randomForestR.R")
source("svmR.R")
source("Rquality.R")
source("modelBayesinteraction.R")

options(shiny.maxRequestSize=10*1024^2) 

data_input <- reactive({
    req(input$file1)
    fread(input$file1$datapath)
})

observeEvent(data_input(),{
    choices <- c(not_sel,names(data_input()))
    updateSelectInput(inputId = "ErrorVar1", choices = choices)
})

ErrorVariable <- eventReactive(input$run_button,input$ErrorVar1)


reactiveDF <- eventReactive(input$run_button,{

    
    df <- read_csv(input$file1$datapath)
    showModal(modalDialog("Fitting the best clustering model... Please wait...", footer=NULL))
    clust_variables <- run_clustering(df,ErrorVariable())
    removeModal()
    
    
    dat <- list(tibble(variable = clust_variables, method = "clustering")
                #tibble(variable = knn_variables, method = "knn"),
                #tibble(variable = randomforest_variable,  method = "Random Forest"),
                #tibble(variable = svm_variable ,method = "SVM")
    ) %>% bind_rows()
    
    return(dat)
})

I guess selectInput returns the name of the column I selected in the UI part, but it fails when I use it within the knn function I use. The function I defined has two inputs, and ErrorVariable should return the column name I selected.

run_knn <- function(data, ErrorVariable){

Can anybody help? I really appreciate it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source