R shiny csv or excel upload option
<p>I have a requirement of giving users an option to upload a file in .csv/.txt or .xlsx format.</p>

<p>I am using xlsx package and have provided a radio button on my UI such as </p>

<pre><code>ui &lt;- dashboardPage(
  dashboardHeader(title = "SKU Health Check App"),
  dashboardSidebar(
    width = 350,
    radioButtons(
      "fileType_Input",
      label = h4("Choose File type"),
      choices = list(".csv/txt" = 1, ".xlsx" = 2),
      selected = 1,
      inline = TRUE
    ),
    fileInput(
      'file1',
      h4('Upload Items List'),
      accept = c(
        'text/csv',
        'text/comma-separated-values,text/plain',
        '.csv',
        '.xlsx'
      )
    ),
</code></pre>

<p>and to handle the options in server as </p>

<pre><code>server &lt;- function(input, output, session) {

  # Get the upload file
  get_item_list &lt;- reactive({
    inFile &lt;- input$file1

    if (is.null(inFile)) {
      return(NULL) }

    if (input$fileType_Input == 1) {
      read.csv(inFile$datapath,
               header = TRUE,
               stringsAsFactors = FALSE)
    } else {
      read.xlsx(inFile$datapath,
                header = TRUE,sheetIndex = 1,
                stringsAsFactors = FALSE)
    }
  })
</code></pre>

<p>But I am getting error as my file is not getting read even with option 1 which was working earlier without radio button and if condition. I am unable to debug as the debugger runs the block of code at once.</p>

<p>Can someone help please?</p>

<p>thanks,</p>

<p>Manoj Agrawal</p>