Q:

Reactive arguments unable to coerce closures as list in R Shiny

I'm trying to learn R and I've been working on converting an R script I found into a Shiny app. The issue I've been stuck on now for some time is that I'm trying to store my data in a reactive container, but when I try and access the data I receive the error "unable to coerce type closure to list" when my code tries to generate the output graphs. I know I need to treat reactive objects like methods when I call them, but I'm still having issues.
A section of my code is given below, which is throwing the error (the relevant section is in the server).
library(shiny)
library(base64enc)
library(httr)
library(rjson)
library(bit64)
library(plyr)
library(stringr)
library(urltools)
library(twitteR)
library(ggplot2)

#initialize environment variables
consumerKey <- 'MUwukLPqlXp7pROuci6NGHiIo'
consumerSecret <- 'yCucMwTsjMsXFrrKDnHTyawxgKFzzRMGy3UeEyzGGvlQXzIHAV'
tokenKey <- '4095349632-uOfSHrUmPzbuTYDRkASHfUuJBy0YxCesY6QtWbe'
tokenSecret <- 'FS55U9PqOIBTCo3mbV3bHli7aEXMJEGmGjPlpfrifGeTL'
setup_twitter_oauth(consumerKey, consumerSecret, tokenKey, tokenSecret)
pos <- scan('res/positive-words.txt', what='character', comment.char=';')
neg <- scan('res/negative-words.txt', what='character', comment.char=';')

ui <- fluidPage(
  sliderInput(inputId = "nTweets", 
              label = "Choose a number of tweets to gather", 
              value = 10, min = 1, max = 100),
  textInput(inputId = "term", label = "Enter a hashtag or term to search:", value = "Canada"),
  actionButton(inputId = "go", 
               label = "Go/Refresh"),
  plotOutput("LHist")
)

server <- function(input, output) {

  rv <- reactiveValues()

  title <- eventReactive(input$go, {
    paste("sentiment on", rv$searchTerm, sep=" ")
  })
  tweets <- eventReactive(input$go, {
    searchTwitter(rv$searchTerm, n=rv$Tweets, lang="en")
  })
  Tweets.text <- eventReactive(input$go, {
    laply(tweets, function(t)t$getText())
  })
  analysis <- eventReactive(input$go, {
    score.sentiment(Tweets.text, pos, neg)
  })

  observeEvent(input$go, {
    rv$searchTerm <- input$term
    rv$Tweets <- input$nTweets
  })

  output$LHist <- renderPlot({
    #histogram
    ggplot(data=analysis()) +
      geom_bar(mapping=aes(x=score), binwidth=1) +
      theme_bw() + scale_color_brewer() +
      ggtitle(paste("Lexical analysis'", title()))
  })

}

shinyApp(ui = ui, server = server)

score.sentiment = function(sentences, pos.words, neg.words, .progress='none')
{

  require(plyr)
  require(stringr)
  scores = laply(sentences, function(sentence, pos.words, neg.words) {

    sentence = gsub('[[:punct:]]', '', sentence)
    sentence = gsub('[[:cntrl:]]', '', sentence)
    sentence = gsub('\\d+', '', sentence)
    # remove retweet entities
    sentence = gsub("(RT|via)((?:\\b\\W*@\\w+)+)", "", sentence)
    # remove at people
    sentence = gsub("@\\w+", "", sentence)
    sentence = gsub("http\\w+", "", sentence)
    word.list = str_split(sentence, '\\s+')
    words = unlist(word.list)
    pos.matches = match(words, pos.words)
    neg.matches = match(words, neg.words)
    pos.matches = !is.na(pos.matches)
    neg.matches = !is.na(neg.matches)
    score = sum(pos.matches) - sum(neg.matches)
    return(score)
  }, pos.words, neg.words, .progress=.progress )

  scores.df = data.frame(score=scores, text=sentences)

  return(scores.df)
}

I've tried messing around with the type of reactive container, trying to convert the the data to a dataframe within the reactive context; all to no avail.
Links to the text data I use is here

A:

I managed to fix the issue. The first thing was to eliminate the reactiveValues that I didn't need and just tie the event handlers directly to the inputs:
server <- function(input, output) {

  tweets <- eventReactive(input$go, {
    searchTwitter(input$term, n=input$nTweets, lang="en")
  })

  Tweets.text <- eventReactive(input$go, {
    laply(tweets(), function(t)t$getText())
  })

  analysis <- eventReactive(input$go, {
    score.sentiment(Tweets.text(), pos, neg)
  })}

It seemed that none of the fuctions were running since the reactive values were not set up properly

