Error: No lines available in input

3,128 views
Skip to first unread message

Joshua Stewart

unread,
Jun 28, 2016, 7:52:03 PM6/28/16
to Shiny - Web Framework for R
I posted this on stack overflow as well: 

I am currently writing my first Shiny app and it runs locally on my machine but after being uploaded to shinyapps.io I get the following error: "No lines available in input." I have done some research and this error seems to be a result of the read.table function evaluating the uploads as empty. However, using the same files locally I am not receiving any errors at all. Here is the code:


    library(shiny)

    shinyUI(fluidPage(
      titlePanel("Sentiment Analysis Tool"),
      sidebarLayout(
    sidebarPanel(
      h3("Upload .csv to get it analyzed!"),
      fileInput('file1', 'Choose CSV File',
                accept = c(
                  'text/csv',
                  'text/comma-separated-values',
                  'text/tab-separated-values',
                  'text/plain',
                  '.csv',
                  '.tsv'
                  )
                ),
      tags$hr(),
      numericInput("num", label = "Indicate which column to analyze", value = 1, min = 1, max = 100),
      checkboxInput('header', 'My Data Has Headers', TRUE),
      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   ','),
      radioButtons('quote', 'Quote',
                   c(None='',
                     'Double Quote'='"',
                     'Single Quote'="'"),
                   '"'),
      actionButton("button","Submit",
                   style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
      br(),
      br(),
      downloadButton('downloadData', 'Download Raw Data'),
      downloadButton('downloadPlot', 'Download Plot')
    ),
    mainPanel(
      plotOutput("histOutput")
        )
      )
    ))

    library(shiny)
    library(tm)
    library(SnowballC)
    library(stringr)
    library(Rstem)
    library(sentiment)
    library(ggplot2)
    library(plyr)
    source("polarity.R")

    shinyServer(function(input, output) {
      observeEvent(input$button, {
        output$histOutput <- renderPlot({
      inFile <- input$file1
      if (is.null(inFile))
        return(NULL)
      RR <- try(read.table(inFile$datapath, header=input$header, sep=input$sep, 
                           quote=input$quote), TRUE)
      validate(
        need(class(RR) != 'try-error', "Upload has empty rows, please fix and try again.")
      )
      withProgress(message = 'Plot is Loading',
                   detail = 'This may take a while...', value = 0, {
                     for (i in 1:10) {
                       validate(
                         need(input$num <= ncol(RR), "Something has gone wrong, please double check your selections.")
                       )
                       sent_df <<- polarity(RR[,input$num])
                       incProgress(1/10)
                       Sys.sleep(0.25)
                     }
                   })
      rawdf <<- c(RR[input$num],polarity(RR[,input$num]))
      class_pol <- sent_df[,4]
      histplot <<- plotInput(sent_df,class_pol)
      histplot
      })
    })
      output$value <- reactive({
        input$num
      })
      output$downloadPlot <- downloadHandler(
        filename = function() { paste("SentimentPlot", '.png', sep='') },
        content = function(file) {
          ggsave(file, plot = histplot, device = "png")
        }
      )
      output$downloadData <- downloadHandler(
        filename = function() { paste("RawData", '.csv', sep='') },
        content = function(file) {
          write.csv(rawdf, file)
        }
      )
    })

And the functions from the polarity file:

    polarity = function(x){
      #Convert text to matrix
      pol = as.matrix(x)
      #Remove punctuation, numbers, unnecessary spaces
      gsub("[[:punct:]]|[[:digit:]]|[ \t]{2,}|^\\s+|\\s+$", "", pol)
      #Error handling using tolower
      pol = sapply(pol, try.error)
      #Polarity classification
      pol = classify_polarity(pol, algorithm = "bayes")
      #Use best fit from class_polarity function from column 4
      class_pol = pol[,4]
      #Create dataframe
      data.frame(text=pol, polarity=class_pol, stringsAsFactors=FALSE)
    }

    try.error = function(x)
    {
      # create missing value
      y = NA
      # tryCatch error
      try_error = tryCatch(tolower(x), error=function(e) e)
      # if not an error
      if (!inherits(try_error, "error"))
        y = tolower(x)
      # result
      return(y)
    }

    plotInput <- function(df,x) {
      ggplot(df, aes(x)) +
        geom_bar(aes(y=..count.., fill=x)) +
        scale_fill_brewer(palette="RdGy") +
        labs(x="Polarity Categories", y="Number of Comments") +
        ggtitle("Sentiment Analysis of Comments\n(Classification by Polarity)")
    }



Any help is appreciated.

CHAMI Soufiane

unread,
Oct 5, 2017, 6:57:57 PM10/5/17
to Shiny - Web Framework for R
I had a similar problem. Here is the way I solved it, 

I tried to execute every line alone as long as it's possible. 

I found that the problem is a specific line which return the following error message : 

> TTF=read.csv("TTF.csv",header = T,  sep = ";")
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  pas de lignes disponibles dans l'entrée

What did I do ? 

I went back to the file conatining this data, I diplucated the same csv file and renamed it with a different name (let us say ("TTAF.csv")) (you can open it an copy paste the data). 

went back to my code and changed the name : > TTF=read.csv("TTF.csv",header = T,  sep = ";")


and it worked very well, 




Reply all
Reply to author
Forward
0 new messages