No Description

R.R 845B

1234567891011121314151617181920212223242526272829303132333435363738
  1. library(tidycensus)
  2. library(tidyverse)
  3. library(plumber)
  4. #* Call table
  5. #* @get /table
  6. #* @serializer json
  7. callData = function(table,municipality) {
  8. census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
  9. #year is between 2000 and 2020
  10. #table is dp02pr, dp03, dp04, dp05
  11. #load variables
  12. variables = load_variables(2020,"acs5/profile")
  13. #load variable vectors
  14. codes = variables$name
  15. codesBool = startsWith(codes,table)
  16. codes = codes[codesBool]
  17. labels = variables$label[codesBool]
  18. #pull table
  19. bigTable = get_acs(geography = "county",
  20. state = "PR",
  21. year = 2020,
  22. county = municipality,
  23. survey = "acs5",
  24. variables = codes)
  25. bigTable$Label = labels
  26. bigTable = bigTable[c("Label","estimate","moe")]
  27. return(bigTable)
  28. }