b-ghimire / twitter-sentiment-analysis

R shiny web application to scrape tweets based on user-defined search keyword and perform sentiment analysis of the tweets. Sentiment analysis of tweets consists of classifying tweets into emotion classes (i.e., anger, disgust, fear, joy, sadness and surprise) and also polarity classes (i.e., negative, neutral and positive) using naïve Bayes classifier. The tweets are scraped, classified into sentiment classes and visualized in R using twitteR, sentiment and ggplot2 packages, respectively.
14 stars 14 forks source link

The Application is not functioning #1

Open profibadan opened 9 years ago

profibadan commented 9 years ago

Please do a note with step by step instructions on how to install this application.

Saisha21 commented 7 years ago

library(twitteR) library(sentiment) library(plyr) library(ggplot2) library(RColorBrewer)

loading twitter credentials

load("twitteR_credentials") registerTwitterOAuth(twitCred)

loading the helper functions

source('helpers.R')

# #shinyServer(function(input, output) {

Step 1: Getting the tweets based on search terms

cainfo="cacert.pem" is required for data access

tweets <- reactive ({ searchTwitter(input$searchTerm, cainfo="cacert.pem", n=1000, lang="en") })

Step2: Preprocessing to clean up the tweets

txtTweets <- reactive ({ preprocess_tweet (tweets()) })

output$plot_emotion <- renderPlot({

# Step 3: Emotion sentiment analysis
emotion <- emotionSentimentAnal(txtTweets())

# Step 4: Polarity sentiment analysis
polarity <- polaritySentimentAnal(txtTweets())

# Step 5: Store results in dataframe
results_df <- data.frame(text=txtTweets(), emotion=emotion, polarity=polarity)

# Step 6: Plot distribution of tweet sentiments
if (input$plot_opt == 'emotion') {

  ggplot(results_df) +
    geom_bar(aes(x=emotion, y=..count.., fill=emotion)) +
    ggtitle(paste('Tweet Sentiment Analysis of Search Term "', input$searchTerm, '"', sep='')) +      
    xlab("Emotion Class") + ylab("No of Tweets") +
    scale_fill_brewer(palette="Set1") +
    theme_bw() +
    theme(axis.text.y = element_text(colour="black", size=18, face='plain')) +
    theme(axis.title.y = element_text(colour="black", size=18, face='plain', vjust=2)) + 
    theme(axis.text.x = element_text(colour="black", size=18, face='plain', angle=90, hjust=1)) +
    theme(axis.title.x = element_text(colour="black", size=18, face='plain')) + 
    theme(plot.title = element_text(colour="black", size=20, face='plain', vjust=2.5)) +
    theme(legend.text = element_text(colour="black", size=16, face='plain')) +
    theme(legend.title = element_text(colour="black", size=18, face='plain')) +
    guides(fill = guide_legend(keywidth = 2, keyheight = 2))

} else {

  ggplot(results_df, aes()) +
    geom_bar(aes(x=polarity, y=..count.., fill=polarity), width=0.6) +
    ggtitle(paste('Tweet Sentiment Analysis of Search Term "', input$searchTerm, '"', sep='')) +
    xlab("Polarity Class") + ylab("No of Tweets") +   
    scale_fill_brewer(palette="Set1") +
    theme_bw() +
    theme(axis.text.y = element_text(colour="black", size=18, face='plain')) +
    theme(axis.title.y = element_text(colour="black", size=18, face='plain', vjust=2)) + 
    theme(axis.text.x = element_text(colour="black", size=18, face='plain', angle=90, hjust=1)) +
    theme(axis.title.x = element_text(colour="black", size=18, face='plain')) + 
    theme(plot.title = element_text(colour="black", size=20, face='plain', vjust=2.5)) +
    theme(legend.text = element_text(colour="black", size=16, face='plain')) +
    theme(legend.title = element_text(colour="black", size=18, face='plain')) +
    guides(fill = guide_legend(keywidth = 2, keyheight = 2))

} 

})

}

please help me i am unable to run this code there is an error in the function .