title: Twitter Analysis in R, Error: zero-length inputs cannot be mixed with those of non-zero length when deploying Shiny Application
body: <p>Just started working with Shiny apps. I built out my code in R and everything executed perfect, when I went to run the app it also worked well, but when I go to deploy my the App I am getting errors for zero length inputs and invalid time arguments that cause my plotly charts to fill up with the errors that I think are being executed to the Shiny log:</p>
  
  <p><img src="https://i.stack.imgur.com/RByoh.png" alt="screenshot from deployed app"></p>
  
  <p>From the log:</p>
  
  <pre><code>2016-06-30T20:41:17.225966+00:00 shinyapps[111287]: Listening on http://0.0.0.0:53352
  2016-06-30T20:41:19.584567+00:00 shinyapps[111287]: [1] "Using direct authentication"
  2016-06-30T20:43:40.040666+00:00 shinyapps[111287]: Warning: Error in mapply: zero-length inputs cannot be mixed with those of non-zero length
  2016-06-30T20:43:40.050669+00:00 shinyapps[111287]:     12: fn
  2016-06-30T20:43:40.050676+00:00 shinyapps[111287]:      7: connect$retry
  2016-06-30T20:43:40.050646+00:00 shinyapps[111287]: Stack trace (innermost first):
  2016-06-30T20:43:40.050671+00:00 shinyapps[111287]:     11: doTryCatch
  2016-06-30T20:43:40.050650+00:00 shinyapps[111287]:     85: mapply
  2016-06-30T20:43:40.050672+00:00 shinyapps[111287]:     10: tryCatchOne
  2016-06-30T20:43:40.050677+00:00 shinyapps[111287]:      6: eval
  2016-06-30T20:43:40.050651+00:00 shinyapps[111287]:     84: Map
  2016-06-30T20:43:40.050678+00:00 shinyapps[111287]:      5: eval
  2016-06-30T20:43:40.050653+00:00 shinyapps[111287]:     83: colorize
  2016-06-30T20:43:40.050680+00:00 shinyapps[111287]:      4: eval
  2016-06-30T20:43:40.050654+00:00 shinyapps[111287]:     82: plotly_build
  2016-06-30T20:43:40.050682+00:00 shinyapps[111287]:      2: eval.parent
  2016-06-30T20:43:40.050655+00:00 shinyapps[111287]:     81: as.widget
  2016-06-30T20:43:40.050681+00:00 shinyapps[111287]:      3: eval
  2016-06-30T20:43:40.050657+00:00 shinyapps[111287]:     80: func
  2016-06-30T20:43:40.050673+00:00 shinyapps[111287]:      9: tryCatchList
  2016-06-30T20:43:40.050659+00:00 shinyapps[111287]:     79: output$ta2
  2016-06-30T20:43:40.050674+00:00 shinyapps[111287]:      8: tryCatch
  2016-06-30T20:43:40.050684+00:00 shinyapps[111287]:      1: local
  2016-06-30T20:43:40.050668+00:00 shinyapps[111287]:     13: runApp
  </code></pre>
  
  <p>Again, the following works fine when I run it inside of R and when I go to run the Shiny App:</p>
  
  <p>For the UI I have the following code:</p>
  
  <p>ui.R</p>
  
  <pre><code>ui &lt;- fluidPage(
  
    #title header
    headerPanel("Main Title"),
  
    sidebarPanel(
      selectInput(inputId="stock", label = ("Search Stock"),
                  choices = c("Select","MSFT","JPM","KO"),
                  selected = NULL),#end select input
  
      submitButton(text="Run")
  
                    ),#end sidebar panel
  
    mainPanel(
      tabsetPanel(id="tabs1",
                  tabPanel("Tweet Collection",DT::dataTableOutput('tc')),
                  tabPanel("Twitter Analysis",
                           fluidRow(
                             column(12,align="center",plotlyOutput("ta1")),
                             column(12,align="center",plotlyOutput("ta2"))
                             ))
      )#end tabset panel
    )#end main panel
  )#end fluid page
  </code></pre>
  
  <p>server.R</p>
  
  <pre><code>server &lt;- function(input,output){
  
    m1 = list(
      l = 50,
      r = 50,
      b = 30,
      t = 50,
      pad = 2
    )
  
    m2 = list(
      l = 50,
      r = 50,
      b = 60,
      t = 50,
      pad = 2
    )
  
    newdata &lt;- reactive({
  
      if("MSFT" %in% input$stock){
  
        msft &lt;- c("#MSFT OR Microsoft OR @Microsoft")
        tweetdata &lt;- searchTwitter(msft,lang="en",n=1500)
        tweetdata.df &lt;- twListToDF(tweetdata)
  
        test &lt;- tweetdata.df[,1]
        myvars &lt;- c("text")
        test &lt;- tweetdata.df[myvars]
        newdata &lt;- test[(!duplicated(test)),]
        newdata &lt;- as.data.frame(newdata)
        newdata &lt;- as.data.frame(filter(newdata, !grepl('Bid Now!', newdata$newdata)))
        newdata
  
      } else if("JPM" %in% input$stock){
  
        vector &lt;- c("#JPM OR JPMorgan OR @jpmorgan OR J.P. Morgan")
        tweetdata &lt;- searchTwitter(vector,lang="en",n=1500)
        tweetdata.df &lt;- twListToDF(tweetdata)
  
        test &lt;- tweetdata.df[,1]
        myvars &lt;- c("text")
        test &lt;- tweetdata.df[myvars]
        newdata &lt;- test[(!duplicated(test)),]
        newdata &lt;- as.data.frame(newdata)
        newdata &lt;- as.data.frame(filter(newdata, !grepl('Bid Now!', newdata$newdata)))
        newdata
  
      } else if("KO" %in% input$stock){
  
        ko &lt;- c("#KO OR Coca-Cola OR @CocaCola OR @CocaColaCo OR Coca Cola")
        tweetdata &lt;- searchTwitter(ko,lang="en",n=1500)
        tweetdata.df &lt;- twListToDF(tweetdata)
  
        test &lt;- tweetdata.df[,1]
        myvars &lt;- c("text")
        test &lt;- tweetdata.df[myvars]
        newdata &lt;- test[(!duplicated(test)),]
        newdata &lt;- as.data.frame(newdata)
        newdata &lt;- as.data.frame(filter(newdata, !grepl('Bid Now!', newdata$newdata)))
        newdata
  
      }
  
    })
  
  ####SOME AUTHENTICATION SET UP FOR TWITTER HERE####
  
  #text analysis tab
    output$ta1 &lt;- renderPlotly({
  
      if("Select" %in% input$stock){
  
        plot_ly(x=c(1,2,3,4,5), y=c(1,2,3,4,5))%&gt;%
          layout(title="No Data Selected", margin=m1)
  
      } else if (!("Select" %in% input$stock)){
  
        # analyze the association between frequent terms (i.e., terms which correlate)
        myCorpus &lt;- Corpus(VectorSource(newdata()[,1]))
        toSpace &lt;- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
        myCorpus &lt;- tm_map(myCorpus, toSpace, "/")
        myCorpus &lt;- tm_map(myCorpus, toSpace, "@")
        myCorpus &lt;- tm_map(myCorpus, toSpace, "\\|")
        myCorpus &lt;- tm_map(myCorpus, stripWhitespace)
        myCorpus &lt;- tm_map(myCorpus, tolower)
        myCorpus &lt;- tm_map(myCorpus, removeWords,c(stopwords(kind = "en"),"https","tco","coca","cola","jpm","microsoft","jpmorgan","morgan"))
        myCorpus &lt;- tm_map(myCorpus, removePunctuation)
        myCorpus &lt;- tm_map(myCorpus, removeNumbers)
        myCorpus &lt;- tm_map(myCorpus, stemDocument, "english")
        myCorpus &lt;- tm_map(myCorpus, PlainTextDocument)
        dtm &lt;- TermDocumentMatrix(myCorpus)
        m &lt;- as.matrix(dtm)
        v &lt;- sort(rowSums(m),decreasing=TRUE)
        d &lt;- data.frame(word = names(v),newfreq=v)
  
        plot_ly(x=d[1:10,1], y=d[1:10,2], color=as.ordered(d[1:10,2]), showlegend=F,type='bar') %&gt;%
          layout(title="Most Frequent Words Found in Collected Tweets",margin=m2,xaxis=list(title=" "),yaxis=list(title="Frequency"))
      }
  
    })#end ta1 output
  </code></pre>
  
  <p>I didn't want to add this much code to the post, so I cut off the part with the "ta2" tab, but essentially it is the same thing. I have tried using all of the following for each of the tm_map functions and have gotten nowhere:</p>
  
  <pre><code>myCorpus &lt;- tm_map(myCorpus, tolower, lazy=true) ...etc
  
  myCorpus &lt;- tm_map(myCorpus, content_transformer(tolower)) ...etc
  
  tm_map(r_stats_text_corpus,
                                content_transformer(function(x) iconv(x, to='UTF-8', sub='byte')),
                                mc.cores=1
                                ) ...used this right underneath my corpus call
  </code></pre>
  
  <p>I am pretty sure I have all the needed libraries called in the global.R script, but just in case here are the libraries associated with the app:</p>
  
  <pre><code>library(bitops)
  library(data.table)
  library(dplyr)
  library(ggplot2)
  library(maptpx)
  library(plotly)
  library(plyr)
  library(qdap)
  library(RColorBrewer)
  library(RCurl)
  library(rjson)
  library(ROAuth)
  library(RWeka)
  library(streamR)
  library(textir)
  library(tm)
  library(twitteR)
  library(varhandle)
  library(wordnet)
  library(shiny)
  library(devtools)
  library(rsconnect)
  library(SnowballC)
  </code></pre>
  
  <p>I think it may have something to do with the tm package, but I do not see any warning or errors for functions associated with tm in my Shiny logs for the app. Ideas?</p>