14 de febrero de 2019

Intructions

Here you will find easy instructions to use the marvellous Stupid Shiny APP.

Data source

Each time you call the APP it downloads a bunch of tweets with the function search_tweets(). You just need to select a word as a filter, a number of tweets the APP is going to download and apply changes.

Goals and libraries

The APP contain 3 tabs showing the following:

  1. A boxplot of number of words by source. Something very very useful to be an autentic data analyzer.
  2. A map showing just those tweets geolocated. I mean, as we must know, twitter captures all geolocations, that's for sure, but, data contain just those coords autorized by users…I guess.
  3. A render table of just one column: tweets. Moreover, there is an extra plot comparing the number of followers by group.

Libraries

Libraries will be at the start of ui.R : library(devtools); library(jsonlite); library(rtweet); library(ggplot2); library(dplyr) library(stringi); library(tidytext); library(leaflet); library(yaml); library(stringr); library(shinyjs); library(base64enc); library(httpuv); library(plotly); library(data.table); library(shiny)

ui.R

Here is the code structure for the ui.R document that defines what you see in this APP.

fluidPage(
    headerPanel("Stupid Shiny APP - Useless word analysis"),
    sidebarLayout(
        sidebarPanel(helpText("bla bla bla"),
                     helpText("(1) Pick a word"),
                     helpText("(2) Define the number of tweets you want to analyze"),
                     helpText("(3) Push the button and enjoy the USELESS"),
                     
                     textInput(inputId = "UserOrHashtag",
                               label = "Twitter User or Hashtag:",
                               value = "Roma"),
                     sliderInput("Ntweets", "Maximum number of tweets to capture:",
                                 min=250, max= 5000, value=500, step = 1),
                     submitButton("Update View", icon = icon("refresh")),
                     width = 3),
        mainPanel(
            tabsetPanel(
                tabPanel("Boxplot de kk",plotlyOutput("P1")),
                tabPanel("Miermap",leafletOutput("M1")),
                tabPanel("Tweets and go home",tableOutput("T1"))
            ))))

server.R

Here is the code structure for the ui.R document that defines what you see in this APP. Code has been collapsed and reduced (hard to read) in order to fit the slide length. Most of the complete code is based on a previous exercise Stupid MAP.

shinyServer(function (input, output) {
    tweets <- reactive ({
        #create token
        tweets <- search_tweets(q=input$UserOrHashtag,n=input$Ntweets,include_rts = F) #capture tweets based on inputs
    PLOT1 <- reactive({ # create plot and filter sources before
        #...here tweets() must be prepared to be plotted...
        PLOT1 <- plot_ly(tweets(), y = ~Nwords, type="box", color = ~factor(source))})
    MAP1 <- reactive({ # create map
        MAP1 <- ##create map
        }})
    TABLE1 <- reactive({TABLE1 <- tweets()$text}) # create table
    #OUTPUTS
    output$P1 <- renderPlotly({PLOT1()})
    output$M1 <- renderLeaflet({MAP1()})
    output$T1 <- renderTable({TABLE1()})
})