Selecting target variables

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)
    
     })
  
  ##########

3 posts were merged into an existing topic: How to display the target variable in the check box group input

A post was merged into an existing topic: How to display the target variable in the check box group input