SHINY R reading different versions of excel files based on user selections
<p>I have a shiny app, that reads in files that are uploaded by a user
Different people have different versions of excel. So if a user is using excel 2007 or excel 2010 we use one section of code. If they upload it in excel 2003 we use a different library to read the file. The user specifies in the form which version of excel they have</p>

<p>The function to do this is below</p>

<pre><code>get_data &lt;- function(strFilePath, storageType) {

  if (is.null(strFilePath))
    return(NULL)

  if (storagetType == 'xls2010' || storagetType == 'xls2007'){
      df &lt;- openxlsx:read.xlsx(strFilePath,sheet = 1)
  }
  else if (storagetType == 'xls2003'){
    df &lt;- XLConnect:readWorksheetFromFile(strFilePath)
  } 

  return(df)
}
</code></pre>

<p>To implement this in shiny, i have two widgets. A <code>fileInput</code> and a <code>selectInput</code>. The user selects which version of excel they are running and then selects the file which then is read in by the <code>function get_data</code>. I suspect its because I'm not utilizing the reactivity correctly. When i run the app and upload the file i get the error message</p>

<blockquote>
  <p>Error: object 'storagetType' not found</p>
</blockquote>

<pre><code># Global.R
storage_types &lt;- c(
  "Excel 2010" = "xls2010",
  "Excel 2007" = "xls2007",
  "Excel 2003" = "xls2003"
)

# UI.R
ui &lt;- shinyUI(fluidPage(
 navbarPage("Navbar!",
             # Tab contains all the information to upload a file
             tabPanel("Upload Data",
                      # Side Panel with Options
                      fluidRow(
                        column(4, wellPanel(
                          id = "leftPanel",
                          div(
                            id = "Header",
                            h3("Options", align = "center"),
                            tags$hr()
                            ),

                          div(
                        selectInput("xlsversion", "2.  Select your Excel version", storage_types),
                        fileInput(inputId = 'file1',label =  '3.  Choose An Excel File'), 
                        )
)))))))

# Server.R

server &lt;- shinyServer(
  function(input, output) {
   # When the Browser to the file location gets updated  
    upload_data &lt;- reactive({
      inFile &lt;- input$file1
      if (is.null(inFile))
        return(NULL)
      get_data(inFile$datapath, input$xlsversion)
})

})
</code></pre>