crosstalk icon indicating copy to clipboard operation
crosstalk copied to clipboard

Rendering crosstalk output

Open abigail-drummond opened this issue 3 years ago • 0 comments

Hi, I am new to crosstalk and I am trying to use it to place a tmap next to a ggplot. To make these html widgets, I've used tmap_leaflet for the tmap object and ggplotly for the ggplot object. When I run the code in RStudio, it prints just fine; however, when I attempt to knit the entire document as a flexdashboard, it no longer works. Can anyone provide any insights into why this might be happening? My code is below. Any and all insights are welcome!

Worcester_income$GEOID <- as.character(Worcester_income$GEOID)
Worcester_income$Median_Household_Income <- as.numeric(Worcester_income$Median_Household_Income)
Worcester_income <- Worcester_income[-c(1),]

geocoded_Worcester_income <- merge(Worcester_census_tracts, Worcester_income, by="GEOID")

# Worcester_income <- read.csv("/Users/abigaildrummond/Desktop/TIGOR/Worcester MA Dashboard/Low_to_Moderate_Income_Population_by_Tract.csv") %>% select(GEOID, LOWMODPCT)
# 
# geocoded_Worcester_income <- merge(Worcester_census_tracts, Worcester_income, by="GEOID")

## racial breakdown using boxplots
Worcester_income_byrace <- read.csv("/Users/abigaildrummond/Desktop/TIGOR/Worcester MA Dashboard/Income.csv") %>% select(BLACK, AMIN_NAK, ASIAN, NH_PI, OTHER, TWOPLUS, HISPANIC, WHITE)
Worcester_income_byrace <- Worcester_income_byrace[-c(1),]
Worcester_income_byrace[,1:8] <- sapply(Worcester_income_byrace[,1:8], as.numeric)

Worcester_income_byrace <- Worcester_income_byrace %>% pivot_longer(BLACK:WHITE, names_to = "race", values_to = "median_income")

income_map <- tm_shape(geocoded_Worcester_income) +
  tm_polygons(col= "Median_Household_Income")

income_map_leaflet <- tmap_leaflet(income_map)

income_race_graph <- ggplotly(
  ggplot(data=Worcester_income_byrace) +
  geom_boxplot(aes(x= race, y=median_income, fill=race)) +
  scale_x_discrete(limits= c("WHITE", "BLACK", "ASIAN", "HISPANIC", "OTHER", "TWOPLUS"), labels=c("White", "Black", "Asian", "Hispanic", "Other", "Two or More")) +
    theme_minimal() +
    theme(legend.position ="none") +
  labs(title = "Median Household Income by Race, 2019 Estimate", x= "Race or Ethnicity", y="Median Household Income ($)")
)

bscols(income_map_leaflet, income_race_graph)```

abigail-drummond avatar Jul 07 '21 04:07 abigail-drummond