The following guide walks you through how to add local data as layers in your Cancer InFocus (CIF) dashboards. By local data, we mean data that is available to you locally that you would like to permanently add to one or more CIF dashboards.


1. Prepare Local Data

To add local data to your CIF dashboards, you will first need to have the data files prepared and available somewhere on your workstation. For the data to display properly, you will need it to match the counties or Census tracts present in your catchment area. In particular, the data will need to contain the same county or Census tract FIPS codes as are present in the other data files you acquire from CancerInFocus.org. This information should be included in a column named FIPS. Your data should also contain columns named County and State (if county-level data) or Tract, County, and State (if Census tract-level data).

The remainder of the file will include the variable(s) you wish to add. It is recommended that these variables be presented in long format, that is with one observation per row. In long format, the final two columns should be named measure and value and filled in accordingly.

Note: In this tutorial we assume your data is in long format. If your data is in wide format (e.g. with a new column for every new variable) then you will need to add a pivot to the step where the local data file gets read into create_shapefiles_v5-3.R.


2. Create local_measures.csv File

Next, you will need to prepare a file called local_measures.csv that contains information about how your new data should be displayed. A blank version of this file is available in the CIF GitHub repo. This file should contain four columns as described below:

Once you have filled in this file with the appropriate values for all variables being added, save it in the same folder as CIFvars_v5-3.R.


3. Read local_measures.csv into create_shapefiles_v5-3.R

Now that the necessary files have been prepared, you will begin incorporating the local data into the data pre-processing for your CIF dashboards. The first step in doing this is to read information about the new variable(s) into the script and combine them with the existing nice_names dataframe. To do this, add the following code immediately after the variable assignment for nice_names (which occurs in approximately line 22):

more_names = read.csv('local_measures.csv', header = T)

nice_names = rbind(nice_names, more_names)

4. Read Local Data into create_shapefiles_v5-3.R

Finally, you are ready to read in the local data file prepared in Step 1. If this data is at the county level, the following code should be added after the chunk preparing the hf_county dataframe. If your local data is at the Census tract level, this code should be added after the chunk preparing the hf_tract dataframe.

local_data = read.csv('usr/dir/file.csv', header = T) %>%
    mutate(measure = str_replace_all(measure, "_", " "),
           cat = "Category",
           RE = NA,
           Sex = NA) %>%
    left_join(nice_names, by="measure") %>%
    mutate(lbl = case_when(
        fmt == "pct" ~ paste0(round(value*100, 1), "%"),
        fmt == "int" ~ prettyNum(round(value, 2), big.mark = ",")
    )) %>%
    filter(def != "NA") %>%
    select(cat, everything())

A few notes on the above:


5. Combine Local Data with Existing Data

After reading in the local data you will need to combine it with the existing data to incorporate it into your dashboards. This is accomplished by adding the newly assigned local_data dataframe to the bind_rows() function for the variable all_county (if adding county-level data) or all_tract (if adding Census tract-level data).


By completing the above steps, you should be able to add local data into your CIF dashboards.

Note, if the local data you are adding is intended to replace existing data (e.g. if you are bringing in new cancer rates to replace those provide by Cancer InFocus), you will need to remove the corresponding dataframes from the all_county or all_tract variable assignments, as appropriate.

If you run into any issues, or have any comments for improving this tutorial, please contact us at .