Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

R script package tigris: cannot load shapefiles

I am using R script to make a choropleth map visualization. The actual data is confidential, so I cannot show the entire code, but the error comes when I load the shapefiles using 'tigris' package. Power BI Desktop does execute the entire code and makes a beautiful map, but when I publish it to Web, it gives me an error message saying "Error: Download failed; check your internet connection or the status of the Census Bureau website at http://www2.census.gov/geo/tiger/."

All the packages I used in the code are supported by Power BI. Could I get help on how to solve this issue?

 

Here is my code:

 

df_state <- dataset

library(dplyr)
library(tidyr)
library(tidyverse)
library(sf)
library(tmap)

# Downloading a shape file via tigris package
library(tigris) #For downloading the zipcode map
library(curl)
library(httr)
options(tigris_use_cache = TRUE)
geo <- st_as_sf(zctas(cb = TRUE, starts_with = df_state$ZCTA)) 
co <- st_as_sf(counties("California", cb = TRUE)) 
co = st_transform(co , st_crs(geo))

#Merging data & map
df_state.sf = merge(geo, df_state) 

tmap_mode("plot")
tm_shape(co) + tm_borders()

 

 

2 Replies