{"action":"created","issue":{"url":"https://api.github.com/repos/uc-cfss/Discussion/issues/27","repository_url":"https://api.github.com/repos/uc-cfss/Discussion","labels_url":"https://api.github.com/repos/uc-cfss/Discussion/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/uc-cfss/Discussion/issues/27/comments","events_url":"https://api.github.com/repos/uc-cfss/Discussion/issues/27/events","html_url":"https://github.com/uc-cfss/Discussion/issues/27","id":194205682,"number":27,"title":"Making stuff reactive","user":{"login":"futureofmaya","id":17488814,"avatar_url":"https://avatars.githubusercontent.com/u/17488814?v=3","gravatar_id":"","url":"https://api.github.com/users/futureofmaya","html_url":"https://github.com/futureofmaya","followers_url":"https://api.github.com/users/futureofmaya/followers","following_url":"https://api.github.com/users/futureofmaya/following{/other_user}","gists_url":"https://api.github.com/users/futureofmaya/gists{/gist_id}","starred_url":"https://api.github.com/users/futureofmaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/futureofmaya/subscriptions","organizations_url":"https://api.github.com/users/futureofmaya/orgs","repos_url":"https://api.github.com/users/futureofmaya/repos","events_url":"https://api.github.com/users/futureofmaya/events{/privacy}","received_events_url":"https://api.github.com/users/futureofmaya/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-07T23:37:03Z","updated_at":"2016-12-08T00:06:53Z","closed_at":null,"body":"Ok, good news! The whole mess is happily published [here](https://ritabiagioli.shinyapps.io/HW10/). \r\n\r\nI have NOT A CLUE why it only likes the repo for hw10. But so be it.\r\n\r\nExcept don't check just now because I just updated it. But it should be up again soon.\r\n\r\nI did at one point get the sentiment analysis to work, but it wasn't reactive. Then I tried to make it reactive. Then I got this error: \r\n\r\nError: no applicable method for 'as.lazy' applied to an object of class \"c('standardGeneric', 'genericFunction', 'function', 'OptionalFunction', 'PossibleMethod', 'optionalMethod')\"\r\n\r\nHere's the code: \r\n\r\n```r\r\nlibrary(shiny)\r\nlibrary(tidyverse)\r\nlibrary(readr)\r\nlibrary(dplyr)\r\nlibrary(ggplot2)\r\nlibrary(twitteR)\r\nlibrary(httpuv)\r\nlibrary(scales)\r\nlibrary(tm)\r\nlibrary(stringr)\r\nlibrary(wordcloud)\r\nlibrary(knitr)\r\nlibrary(tidytext)\r\nlibrary(syuzhet)\r\nlibrary(lubridate)\r\nlibrary(scales)\r\nlibrary(reshape2)\r\nlibrary(dplyr )\r\nlibrary(rtweet)\r\nlibrary(feather)\r\nlibrary(RColorBrewer)\r\nlibrary(rsconnect)\r\n\r\ntweetswords <-read_csv(\"tweetswords.csv\") %>%\r\n  distinct()\r\n\r\nreg <- \"([^A-Za-z\\\\d#@']|'(?![A-Za-z\\\\d#@]))\"\r\n\r\ntweet_words <-tweetswords %>%\r\n  filter(!str_detect(text, '^\"')) %>%\r\n  mutate(text = str_replace_all(text, \"https://t.co/[A-Za-z\\\\d]+|&amp;\", \"\")) %>%\r\n  unnest_tokens(word, text, token = \"regex\", pattern = reg) %>%\r\n  filter(!word %in% stop_words$word,\r\n         str_detect(word, \"[a-z]\"))\r\n\r\nimmigrant_tweets_with_sentiment <- read_csv(\"immigrant_tweets_with_sentiment.csv\") %>%\r\n  distinct()\r\n\r\n#Server Code\r\nshinyServer(function(input, output) {\r\n  \r\n  #Filter Tweets\r\n  filtered_tweets <- reactive({\r\n    if(is.null(input$word)) {\r\n      return(NULL)\r\n    }\r\n    \r\n    #Function to take term input, filter, and inner join with other words\r\n    tweet_words %>%\r\n      filter(word %in% input$word) %>%\r\n      select(id) %>%\r\n      unique() %>%\r\n      inner_join(tweet_words)\r\n  })\r\n  filtered_tweets2 <- reactive({\r\n    if(is.null(input$word)) {\r\n      return(NULL)\r\n    }\r\n    immigrant_tweets_with_sentiment %>%\r\n      filter(text %in% input$word) %>%\r\n      select_(id) %>%\r\n      unique() %>%\r\n      inner_join(immigrant_tweets_with_sentiment)\r\n  })\r\n    \r\n    \r\n  # create input for words\r\n  output$wordInput <- renderUI({\r\n    selectizeInput(\r\n      \"word\",\r\n      \"Words\",\r\n      choices = sort(unique(tweet_words$word)),\r\n      multiple = TRUE\r\n    )\r\n  })\r\n  \r\n  output$wordcloud <- renderPlot({\r\n    if(is.null(filtered_tweets())){\r\n      return()\r\n    }\r\n    \r\n    tweet_words_count <- filtered_tweets() %>%\r\n      count(word, sort = TRUE) %>%\r\n      arrange(desc(n)) %>%\r\n      filter(word != \"immigration\",\r\n             word != \"immigrant\",\r\n             word != \"#immigration\",\r\n             word != \"immigrants\")\r\n    \r\n    wordcloud(words = tweet_words_count$word, freq = tweet_words_count$n, scale=c(8,.3),\r\n              min.freq = 50, random.order = FALSE, rot.per=.15, colors = brewer.pal(8,\"Dark2\"))\r\n  })\r\n  output$sentiment <- renderPlot({\r\n    if(is.null(filtered_tweets())){\r\n      return()\r\n    }\r\n    \r\n    tweets_for_sentiment <- filtered_tweets2() %>%\r\n      filter(word != \"immigration\",\r\n             word != \"immigrant\",\r\n             word != \"#immigration\",\r\n             word != \"immigrants\")\r\n    \r\n    sentimentTotals <- data.frame(colSums(tweets_for_sentiment[,c(\"anger\", \"anticipation\", \"disgust\", \"fear\", \"joy\", \"sadness\", \"surprise\", \"trust\")]))\r\n    names(sentimentTotals) <- \"count\"\r\n    sentimentTotals <- cbind(\"sentiment\" = rownames(sentimentTotals), sentimentTotals)\r\n    rownames(sentimentTotals) <- NULL\r\n    \r\n    ggplot(data = sentimentTotals, aes(x = sentiment, y = count)) +\r\n      geom_bar(aes(fill = sentiment), stat = \"identity\") +\r\n      theme(legend.position = \"none\") +\r\n      xlab(\"Sentiment\") + ylab(\"Total Count\") + ggtitle(\"Sentiment Score for Tweets with Selected Word(s)\")\r\n  })\r\n  \r\n})\r\n```\r\n\r\nIf you have any thoughts... they are welcome. It was giving me something weird about id before so I used select_(). Not sure if that did anything at all."},"comment":{"url":"https://api.github.com/repos/uc-cfss/Discussion/issues/comments/265613678","html_url":"https://github.com/uc-cfss/Discussion/issues/27#issuecomment-265613678","issue_url":"https://api.github.com/repos/uc-cfss/Discussion/issues/27","id":265613678,"user":{"login":"futureofmaya","id":17488814,"avatar_url":"https://avatars.githubusercontent.com/u/17488814?v=3","gravatar_id":"","url":"https://api.github.com/users/futureofmaya","html_url":"https://github.com/futureofmaya","followers_url":"https://api.github.com/users/futureofmaya/followers","following_url":"https://api.github.com/users/futureofmaya/following{/other_user}","gists_url":"https://api.github.com/users/futureofmaya/gists{/gist_id}","starred_url":"https://api.github.com/users/futureofmaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/futureofmaya/subscriptions","organizations_url":"https://api.github.com/users/futureofmaya/orgs","repos_url":"https://api.github.com/users/futureofmaya/repos","events_url":"https://api.github.com/users/futureofmaya/events{/privacy}","received_events_url":"https://api.github.com/users/futureofmaya/received_events","type":"User","site_admin":false},"created_at":"2016-12-08T00:06:53Z","updated_at":"2016-12-08T00:06:53Z","body":"It might be something about the fact that for the wordcloud, everything is separated into words and we're trying to match a specific word, but for the sentiment analysis, we're trying to find a word in a column titled text that contains the whole tweet. I tried to account for that... but not sure if I actually did or not. "}}
{"actor":{"display_login":"futureofmaya"}}