The goal of this document is to describe how and why we created The Generality Widget and how we made it, focusing on:
- What data we used
 - How we coded the data
 - How we prepared the data
 - How we analyzed the data
 
| from facebook_scraper import get_posts | |
| import pandas as pd | |
| import time | |
| import json | |
| # param | |
| n_pages_to_iterate = 100 # number of pages to scrape within one FB page | |
| # reading data with page names | |
| district_data = pd.read_csv("2020-2021-critical-race-posts-schools-districts.csv") | 
| from facebook_scraper import * | |
| import pandas as pd | |
| set_user_agent("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)") | |
| page = pd.DataFrame() | |
| for post in get_posts('245937932251091/posts/2129192957258903', pages=10 ,options={"comments": True}, credentials = ("[email protected]","025021")): | |
| page = page.append(post, ignore_index = True) | 
| library(tidyverse) | |
| library(googlesheets4) | |
| # this is an example Google Sheet | |
| d <- read_sheet("https://docs.google.com/spreadsheets/d/1kz2LlLgXkN_HaBEAiFETl59b09u9AwMIgrwQx6DCv8A/edit#gid=0", col_names = FALSE) | |
| prep_otter_transcript <- function(d, length_less_than_100_min) { | |
| d <- d %>% rename(x1 = 1) | 
| # apply for access to Twitter's academic program: https://developer.twitter.com/en/solutions/academic-research | |
| library(academictwitteR) | |
| library(rtweet) | |
| library(tidytags) # must be installed first with: remotes::install_github("ropensci/tidytags") | |
| bearer_token <- "xxx" # Insert bearer token from developer.twitter.com from the your academic account | |
| trial <- get_all_tweets("#BAmazonUnion OR #UnionizeAmazon", "2020-01-01T00:00:00Z", "2021-05-01T00:00:00Z", bearer_token, data_path = NULL) | 
| library(tidyverse) | |
| library(tidytuesdayR) | |
| library(janitor) | |
| tt_output <- tt_load_gh(last_tuesday()) | |
| list_of_d <- tt_download(tt_output) | |
| d <- list_of_d$animal_complaints | |
| d %>% | 
| library(tidyverse) | |
| library(readxl) | |
| d <- read_excel("Downloads/Public-Dataset-Age.xlsx") | |
| d %>% | |
| mutate(month = lubridate::month(DATE, label = TRUE)) %>% | |
| group_by(month, AGE_RANGE) %>% | |
| summarize(total_cases = sum(NEW_ARCASES)) %>% | |
| filter(AGE_RANGE != "Pending") %>% | |
| mutate(total_cases_prop = total_cases / sum(total_cases)) %>% | |
| ggplot(aes(y = total_cases_prop, x = AGE_RANGE, fill = as.factor(month))) + | 
| library(shiny) | |
| ui <- fluidPage( | |
| titlePanel("How Many Reviewers?"), | |
| sidebarLayout( | |
| sidebarPanel( | |
| numericInput("n_papers", "Number of Anticipated Papers", 100), | |
| numericInput("n_reviews", "Number of Reviews Per Paper", 3), | 
| library(shiny) | |
| library(tidyverse) | |
| d <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv") | |
| states <- d %>% | |
| pull(state) %>% | |
| unique() %>% | |
| sort() | 
| # | |
| # This is a Shiny web application. You can run the application by clicking | |
| # the 'Run App' button above. | |
| # | |
| # Find out more about building applications with Shiny here: | |
| # | |
| # http://shiny.rstudio.com/ | |
| # | |
| library(shiny) |