Shiny server input and brashed points

I am not being able to succesfully get the brushed points if I use server input. If I use the file specific variable names suh as wt and mpg from mtcars, the brushed points get selected without error, but if I use the input$variable name it does not work. Please see below. When I use the commented line, the brushed points function works well, but if I use the variable names that I get through the input box (input$variable), I get the message below.

...Warning: Error in brushedPoints: brushedPoints: xvar ('mtcars[, c(input$variable)]')
not in names of input...

I do not understand because the plot displays with user input.

library(shiny)
library(ggplot2)

# Define server logic required to draw a histogram
function(input, output, session) {
  
  output$data <- renderTable({
    mtcars[, c(input$variable), drop = FALSE]
  }, rownames = TRUE)
  
  
  output$data2 <- renderTable({
    mtcars[, c(input$variable2), drop = FALSE]
  }, rownames = TRUE)
  
  output$summary <- renderText({
    paste("SUMMARY STATISTICS")
  })
  output$sum <- renderTable({
    summary(mtcars)
  })

  output$plot <- renderPlot({
    ggplot(mtcars, aes(mtcars[,c(input$variable)], mtcars[, c(input$variable2)])) + geom_point()
  })
  
#  output$plot <- renderPlot({
 #   ggplot(mtcars, aes(wt, mpg)) + geom_point()
 # }, res = 96)
  
  output$data3 <- renderTable({
    brushedPoints(mtcars, input$plot_brush)
  })

I have solved the problem in the following way:


library(shiny)
library(ggplot2)



# Define server logic required to draw a histogram
function(input, output, session) {
  
  output$data <- renderTable({
    mtcars[, c(input$variable), drop = FALSE]
  }, rownames = TRUE)
  
  
  output$data2 <- renderTable({
    mtcars[, c(input$variable2), drop = FALSE]
  }, rownames = TRUE)
  
  output$summary <- renderText({
    paste("SUMMARY STATISTICS")
  })
  output$sum <- renderTable({
    summary(mtcars)
  })

  output$plot <- renderPlot({
    ggplot(mtcars, aes(mtcars[,c(input$variable)], mtcars[, c(input$variable2)])) + geom_point() + geom_smooth(method='lm', se=FALSE)
  })
  
  output$data3 <- renderTable({
   brushedPoints(mtcars, input$plot_brush, xvar = input$variable, yvar =  input$variable2)
  })

}