title: How can I set variable x as default when I upload a .CSV file on my App?
body: <p>My Shiny Application's purpose is to upload a .csv file and plot a ggplot graph with its data.
  When I upload a .csv file on my Shiny Application, the default variable is "y" for both input variables. However, when I change "y" to "x" on the "X Variable" input, the App works fine.
  I just have to set "x" for "X Variable" input and "y" for "Y Variable" input as default when I upload the .csv file.</p>
  
  <p>Here follows the app.R code with my comments and Error Message I get when I upload the file.</p>
  
  <pre><code>library(shiny)
  library(datasets)
  library(ggplot2)
  
  ui &lt;- shinyUI(fluidPage(
    titlePanel("Column Plot"),
    tabsetPanel(
      tabPanel("Upload File",
               titlePanel("Uploading Files"),
               sidebarLayout(
                 sidebarPanel(
                   fileInput('file1', 'Choose CSV File',
                             accept=c('text/csv', 
                                      'text/comma-separated-values,text/plain', 
                                      '.csv')),
  
                   tags$br(),
                   checkboxInput('header', 'Header', TRUE),
                   radioButtons('sep', 'Separator',
                                c(Comma=',',
                                  Semicolon=';',
                                  Tab='\t'),
                                ','),
  
                   selectInput('xcol', 'X Variable', "", selected = NULL),
                   selectInput('ycol', 'Y Variable', "", selected = NULL)
  
                 ),
                 mainPanel(
                   tableOutput('contents'),
                   plotOutput('MyPlot')
                 )
               )
      )
    )
  )
  )
  
  
  server &lt;- shinyServer(function(input, output, session) {
  
    data &lt;- reactive({ 
      req(input$file1)
  
      inFile &lt;- input$file1 
  
      df &lt;- read.csv(inFile$datapath, header = input$header, sep = input$sep)
  
      ## Update inputs
      ## I've already tried to change the selected = names(df) to selected = NULL on this part of the server code, but it didn't work.
  
      updateSelectInput(session, inputId = 'xcol', label = 'X Variable',
                        choices = names(df), selected = names(df))
      updateSelectInput(session, inputId = 'ycol', label = 'Y Variable',
                        choices = names(df), selected = names(df)[2])
  
      return(df)
    })
  
    output$contents &lt;- renderTable({
      data()
    })
  
    output$MyPlot &lt;- renderPlot({
  
      xy &lt;- data()[, c(input$xcol, input$ycol)]
      ggplot(data = xy, aes(x, y)) +
        geom_line() +
        geom_point()
  
    })
  })
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>The error message I get is:</p>
  
  <blockquote>
    <p>"Error: object 'x' not found".</p>
  </blockquote>