How to display the target variable in the check box group input

...HI,

i am anjana trying to create a shiny application for the random forest algorithm by taking the users input csv, that part is shown in the above figure

now i have a problem with displaying the column names in the feature variables and target variables. i just given all the variable names to the both checkbox group and select input group.

i have a problem here when i select the feature variable , from the checkbox group it should automatically remove from the target variables(select input box). can any one help me with best lines.

 # Define server logic required to draw a histogram
server <- function(input, output) {
  
  # Read file ----
  df <- reactive({
    req(input$uploaded_file)
    read.csv(input$uploaded_file$datapath,
             header = input$header,
             sep = input$sep)  
    
  })
  
  
  # Dynamically generate UI input when data is uploaded ----
  output$checkbox <- renderUI({
           checkboxGroupInput(inputId = "select_var", 
                       label = "Select Feature variables", 
                       choices = names(df()),
                       selected = names(df_sel_tar()))
    
                       
  })
  output$selectbox<-renderUI({
    selectInput(inputId = "select_var_tar",
                label = "Select Target Variable",
                choices = names(df()))
  })
  
 df_drop<-reactive({
   
 req(input$select_var_tar)
   drop(input$select_var_tar)
   df_drop<-df() %>% df[,!names(df() % in % drop)]
     
    })
      
  # Select columns to print ----
  df_sel <- reactive({
    req(input$select_var)
    df_sel <- df() %>% select(input$select_var)
 
     })
  

  
  df_sel_tar <- reactive({
    req(input$select_var_tar)
    
    df_sel_tar <- df() %>% select(input$select_var_tar)
    
     })

##############
here is the code in this df_drop() we should write the code to drop the selected target variable from the select box input. once it gets selected from the sleeted box it should not appear in the checkbox group.

Split from thread: How to select variables using data table


i have issue with target variable can you help me with the solution.


i just try to select the target column and feature columns here the main issue is

when we select the target variable from the select box , that selected variable should not appear in the check box group . i mean we should deactivate that selected variable in checkbox group


fluidPage(
                                                    sidebarLayout(
                                                      sidebarPanel(
                                                        p(h4("Please upload a CSV formatted file with your data.")),
                                                        fileInput("uploaded_file", "Choose CSV File",
                                                                  multiple = TRUE,
                                                                  accept = c("text/csv",
                                                                             "text/comma-separated-values,text/plain",
                                                                             ".csv")),
                                                        
                                                        # Horizontal line ----
                                                        tags$hr(),
                                                        
                                                        # Input: Checkbox if file has header ----
                                                        checkboxInput("header", "Header", TRUE),
                                                        
                                                        # Input: Select separator ----
                                                        radioButtons("sep", "Separator",
                                                                     choices = c(Semicolon = ";",
                                                                                 Comma = ",",
                                                                                 Tab = "\t"),
                                                                     selected = ","),
                                                        
                                                        
                                                        # Horizontal line ----
                                                        tags$hr(),
                                                        
                                                        # Input: Select number of rows to display ----
                                                        radioButtons("disp", "Display",
                                                                     choices = c(All = "all",
                                                                                 Head = "head"),
                                                                     selected = "head"),
                                                        
                                                        # Select variables to display ----
                                                        uiOutput("selectbox"),
                                                        tags$hr(),
                                                        uiOutput("checkbox")
                                                      ),
                                                      

# Define server logic required to draw a histogram
server <- function(input, output) {
  
  # Read file ----
  df <- reactive({
    req(input$uploaded_file)
    read.csv(input$uploaded_file$datapath,
             header = input$header,
             sep = input$sep)  
    
  })
  
  
  # Dynamically generate UI input when data is uploaded ----
  output$checkbox <- renderUI({
           checkboxGroupInput(inputId = "select_var", 
                       label = "Select Feature variables", 
                       choices = names(df()),
                       selected = names(df()))
    
                       
  })
  output$selectbox<-renderUI({
    selectInput(inputId = "select_var_tar",
                label = "Select Target Variable",
                choices = names(df()))
 
     })
  
  
  df_drop <- reactive({
  mydata=df[,grepl("input$select_var_tar",names(df()))]   
    })
 
 
 
  # Select columns to print ----
  df_sel <- reactive({
    req(input$select_var)
    df_sel <- df() %>% select(input$select_var)
 
     })
  

  
  df_sel_tar <- reactive({
    req(input$select_var_tar)
    
    df_sel_tar <- df() %>% select(input$select_var_tar)
    
     })
  
  ##########
  df_drop <- reactive({
  mydata=df[,grepl("input$select_var_tar",names(df()))]   
    })

This looks like the problem. Remove the quotes so it's just

df_drop <- reactive({
  mydata = df[, grepl(input$select_var_tar, names(df()))]
})

Hi, nasthan ,
Thank you so much for your reply but i couldn't get the solution for that will you advise me any code similar to my problem

https://touchstone.shinyapps.io/MLapplication/

this is my application when you upload your csv, it asks to select the features of your variables, and as well as with target variable .

once you select the target variable from the select box, that column should not be highlighted in checkbox group.

this is the my issue can you provide the solution.

Thanks and Regrads

K. ANJANA NARAYANA

screen shot for the application