title: Reading the name of the two columns from two radiobuttons and put their vectors in one dataframe in R Shiny
body: <p>I have a set of built-in data. The goal is to read in the names of two columns from two RadioButtons and then, making a DataFrame from the chosen columns. I make this reproducible example here. </p>
  
  <p>If you run the</p>
  
  <pre><code> output$mytable = renderDataTable(vector1)
  </code></pre>
  
  <p>or</p>
  
  <pre><code> output$mytable = renderDataTable(vector2)
  </code></pre>
  
  <p>separately, you'll find each one of observeEvents is working properly but I'm stuck and I can't put those columns together.</p>
  
  <p>P.S.1. I know the last two lines will give an error because there is no <code>vector1</code> and <code>vector2</code> at first. Therefore, I put # to make them comments.</p>
  
  <p>P.S.2. I need to use the resultant data frame in another place. That's why I'm insisting on forming one data frame.</p>
  
  <pre><code>library(shiny)
  
  vchoices &lt;- 1:ncol(mtcars)
  names(vchoices) &lt;- names(mtcars)
  
  runApp(list(
    ui = basicPage(
      h2('The mtcars data'),
      radioButtons(
        "column1",
        "select columns",
        choices = vchoices,
        inline = T
      ),
      radioButtons(
        "column2",
        "select columns",
        choices = vchoices,
        inline = T
      ),
      dataTableOutput('mytable')
    ),
  
    server = function(input, output) {
      observeEvent(input$column1, {
        cols1 &lt;- as.numeric(input$column1)
        vector1 &lt;- data.frame(mtcars[, cols1])
        names(vector1) &lt;- c("Firstcolumn")
        #output$mytable = renderDataTable(vector1)
      })
  
      observeEvent(input$column2, {
        cols2 &lt;- as.numeric(input$column2)
        vector2 &lt;- data.frame(mtcars[, cols2])
        names(vector2) &lt;- c("Firstcolumn")
        #output$mytable = renderDataTable(vector2)
      })
      #z &lt;- cbind(vector1, vector2)
      #output$mytable = renderDataTable(z)
      }
   ))
  </code></pre>