January, 2018
Day 2 - Shiny Project
twitter API
twitter API
Exercise
Functions:
- Write the following functions:
- A function that downloads data from twitter. It has two inputs the username and n_obs. This funtion should also transform the data to have the columns: {created, status, longitude, latitude}.
- A function that takes the clean data and tokenises the status and removes stopword.
- A function that takes the tokens and calculates the proportion positive & negative words
- A function that takes the tokens and calculates the number of words for each sentiment exlcuding positive and negative.
- A function that takes the tokens and calculates the number of times the positive and negative words appear. Converts the output to a term matrix where the columns are {positive, negative} and the rownames are the words.
Exercise
Dashboard layout:
- Create a shinydashboard app (ShinyTwitter) with two tabs (Dashboard & Data).
- Add the following inputs to the sidebar:
- A textInput (username) with default value @realDonaldTrump.
- A sliderInput (n_obs) with default value 50.
- A actionButton (refresh).
Exercise
Dashboard tabs
- Data tab
- Create a eventReactive (data) on the refresh button that runs the data import and cleaning function.
- create a dataTableOutput (data_table) that displays the data when the refresh button is clicked.
- Create a reactive (tokens) that runs the tokenise function
- In the dashboard tab create a two column view with width 4 & 8.
Exercise
- Column 1:
- In the first column create 3 valueBoxOutput boxes (observations, positive, negative) where the widths are all 12.
- For the observations valueBox display the number of observations in the data
- For the positive & negative valueBox create a reactive that runs the positive and negative function and then map the correct value to the correct valueBox.
- Column 2:
- Create a reactive that runs the term matrix function
- Add a plotOutput that runs comparison.cloud(tm(),colors = c("red", "green"), max.words = 100 ). Where tm() is the term matrix reactive.
- Create a reactive runs the sentiment function
- add a plotlyOutput that shows a barchart of the sentiments.
- Add a leafletOutput that displays a marker for each tweet that has a location with a popup that show the tweet when clicked