Skip to content

Commit

Permalink
Split rendering code for counties and places and update .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
awunderground committed Apr 10, 2023
1 parent 9dde021 commit a2fd769
Show file tree
Hide file tree
Showing 278 changed files with 21,834 additions and 134,667 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ rfi-applicants-brief.xlsx
rfi-applicants.xlsx

/.quarto/
factsheets/999*
factsheets/998*
factsheets/999_county-pages/
factsheets/998_place-pages/
2 changes: 1 addition & 1 deletion R/create_standard_county_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if(!file.exists("data/999_all-counties.Rda")) {

geoid_lst <- as.list(prepped_counties$geoid)

prepped_counties <- tibble(filename = "index.html",
prepped_counties <- tibble(filename = "index-county.html",
params = map(geoid_lst,
~list(state_county = .,
state_title = FALSE)
Expand Down
39 changes: 39 additions & 0 deletions R/create_standard_place_df.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#Code to create data for standard factsheets for places

#Gabe Morrison

#2023-03-15

library(tidyverse)
library(tidycensus)

if(!file.exists("data/998_all-places.Rda")) {

place_geoids <- read_csv(here("mobility-metrics", "place-populations.csv")) %>%
filter(year == 2020)

prepped_places <- place_geoids %>%
mutate(GEOID = paste0(state, place)) %>%
select(geoid = GEOID) %>%
mutate(state_title = list(state_title = FALSE),
geoid = str_c(geoid, ";"),
geoid = strsplit(geoid, ";")
)

geoid_lst <- as.list(prepped_places$geoid)

prepped_places <- tibble(filename = "index.html",
params = map(geoid_lst,
~list(state_place = .,
state_title = FALSE)
),
dir_name = str_c("factsheets/998_place-pages/", geoid_lst, "/")
)

save(prepped_places, file = "data/998_all-places.Rda")

} else {

load("data/998_all-places.Rda")

}
16 changes: 0 additions & 16 deletions R/load_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ load_data <- function() {
)
) %>%
left_join(county_names, by = c("state", "county")) %>%
mutate(
share_debt_col_ub = 0,
share_debt_col_lb = 1,

digital_access = 0.1234,
digital_access_quality = 3

) %>%
prep_data()

data_years <- read_csv(
Expand All @@ -47,14 +39,6 @@ load_data <- function() {
.default = col_double()
)
) %>%
mutate(
election_turnout = 0.1234,
election_turnout_quality = 3,

digital_access = 0.1234,
digital_access_quality = 3

) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

Expand Down
76 changes: 76 additions & 0 deletions R/load_place_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
load_place_data <- function() {

my_col_type <- cols(
state = col_character(),
county = col_character()
)

county_names <- read_csv(here("mobility-metrics", "old", "01_mobility-metrics.csv")) %>%
select(state, county, state_name, county_name) %>%
distinct()

data_recent <- read_csv(
here("mobility-metrics", "00_mobility-metrics_recent.csv"),
col_type =
cols(
state = col_character(),
county = col_character(),
ratio_black_nh_house_value_households = col_character(),
ratio_hispanic_house_value_households = col_character(),
ratio_other_nh_house_value_households = col_character(),
ratio_white_nh_house_value_households = col_character(),
ratio_population_pc_physician = col_character(),
.default = col_double()
)
) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

data_years <- read_csv(
here("mobility-metrics","00_mobility-metrics_longitudinal.csv"),
col_type = cols(
state = col_character(),
county = col_character(),
ratio_black_nh_house_value_households = col_character(),
ratio_hispanic_house_value_households = col_character(),
ratio_other_nh_house_value_households = col_character(),
ratio_white_nh_house_value_households = col_character(),
ratio_population_pc_physician = col_character(),
.default = col_double()
)
) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

data_race_ethnicity <- read_csv(
here("mobility-metrics", "01_mobility-metrics_race-ethnicity_recent.csv"),
col_types = my_col_type
) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

data_race <- read_csv(
here("mobility-metrics", "02_mobility-metrics_race_recent.csv"),
col_types = my_col_type
) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

data_race_share <- read_csv(
here("mobility-metrics", "03_mobility-metrics_race-share_recent.csv"),
col_types = my_col_type
) %>%
left_join(county_names, by = c("state", "county")) %>%
prep_data()

data_list <- list(
recent = data_recent,
years = data_years,
race_ethnicity = data_race_ethnicity,
race = data_race,
race_share = data_race_share
)

return(data_list)

}
24 changes: 19 additions & 5 deletions R/quarto_render_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ quarto_render_wrapper <- function(input, output_file, execute_params, dir_name)
if (!file.exists(template_name)) {

file.copy(
from = "index.qmd",
from = input,
to = template_name
)

}

# copy index.qmd
# copy project yaml
yaml_name <- paste0(dir_name, "_quarto.yml")
if (!file.exists(yaml_name)) {

Expand All @@ -45,7 +45,7 @@ quarto_render_wrapper <- function(input, output_file, execute_params, dir_name)

}

# copy description qmd
# copy description .qmd
description_qmd_name <- paste0(dir_name, "description.qmd")
if (!file.exists(description_qmd_name)) {

Expand All @@ -59,14 +59,28 @@ quarto_render_wrapper <- function(input, output_file, execute_params, dir_name)
# copy description html
description_html_name <- paste0(dir_name, "description.html")
if (!file.exists(description_html_name)) {

file.copy(
from = "description.html",
from = "description.html",
to = description_html_name
)

}

www_name <- paste0(dir_name, "www")
if (!file.exists(www_name)) {

dir.create(www_name)

file.copy(
from = "www",
to = dir_name,
recursive = TRUE
)

}


quarto_render(
input = template_name,
output_file = output_file,
Expand Down
4 changes: 2 additions & 2 deletions R/render_pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#'
#' @returns pwalk implicitly returns the list inputted to it. The return objects
#' are not used for this function, however.
render_pages <- function(prepped_object, input = "index.qmd", workers = 1) {
render_pages <- function(prepped_object, input, workers = 1) {

future::plan(future::multisession, workers = workers)

Expand All @@ -33,7 +33,7 @@ render_pages <- function(prepped_object, input = "index.qmd", workers = 1) {

prepped_object %>%
select(to = dir_name) %>%
pwalk(file.copy, from = "www", recursive = TRUE, overwrite = TRUE) %>%
#pwalk(file.copy, from = "www", recursive = TRUE, overwrite = TRUE) %>%
pwalk(file.copy, from = "site_libs", recursive = TRUE, overwrite = TRUE) #%>%
#pwalk(file.copy, from = "description.html", overwrite = TRUE)

Expand Down
18 changes: 16 additions & 2 deletions create_standard_pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,32 @@ library(quarto)
library(tidycensus)

source("R/create_standard_county_df.R")
source("R/create_standard_place_df.R")
source("R/quarto_render_wrapper.R")
source("R/render_pages.R")

#For testing:
# small <- prepped_counties %>%
small_county <- prepped_counties %>%
slice_head(n = 4)

tictoc::tic()
render_pages(prepped_object = small_county, workers = 4, input = "index-county.qmd")
tictoc::toc()

# small_place <- prepped_places %>%
# slice_head(n = 4)
#
# tictoc::tic()
# render_pages(prepped_object = small, workers = 4)
# render_pages(prepped_object = small_place, workers = 4, input = "index-place.qmd")
# tictoc::toc()



#For actual run:
tictoc::tic()
render_pages(prepped_object = prepped_counties, workers = 96)
tictoc::toc()

tictoc::tic()
render_pages(prepped_object = prepped_places, workers = 96)
tictoc::toc()
Binary file added data/998_all-places.Rda
Binary file not shown.
2 changes: 1 addition & 1 deletion description.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ This metric highlights racial and ethnic disparities in an important source of w

<br>

## <span style="color:#8A9191">Pillar: Healthy Environment and Good Access to Healthcare</span>{#pillar-healthy-environment-and-access-to-good-health-care}
## <span style="color:#8A9191">Pillar: Healthy Environment and Access to Good Healthcare</span>{#pillar-healthy-environment-and-access-to-good-health-care}

![](www/images/mobility-icons/mobility-infographic-health-icon.png){width=2in fig-align="center"}

Expand Down
Empty file.
145 changes: 98 additions & 47 deletions factsheets/999_county-pages/01001/description.html

Large diffs are not rendered by default.

Loading

0 comments on commit a2fd769

Please sign in to comment.