I'm afraid that in order to help you , I would need a reprex. As I'm unable to recreate your issue without it.
I took the code and initial data that you originally provided, and satisfied myself that there is nothing inherintly wrong with your apprpoach, it works after all. I suppose the devil is in the details which I can't access as of yet.
Here is that test shiny app I created.
The top plot is unfiltered, the bottom one is filtered on State code (iso..)
library(shiny)
library(leaflet)
library(sp)
library(albersusa) #devtools::install_github("hrbrmstr/albersusa")
library(rmapshaper)
spdf <- rmapshaper::ms_simplify(usa_sf(), keep = 0.1)
pal <- colorNumeric("Blues", domain = spdf$pop_2014)
epsg2163 <- leafletCRS(
crsClass = "L.Proj.CRS",
code = "EPSG:2163",
proj4def = "+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs",
resolutions = 2^(16:7))
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("leaflettest"),
sidebarLayout(sidebarPanel (
selectInput(inputId = "iso_3166_2",label="Filter on iso_3166_2",
choices = unique(pull(spdf,iso_3166_2)))
),
mainPanel (
leafletOutput("leafplot1"),
leafletOutput("leafplot2")
)
))
# Define server logic required to draw a histogram
server <- function(input, output) {
unfilteredData1 <- reactive({
spdf
})
filteredData2 <- reactive({
spdf[spdf$iso_3166_2 == input$iso_3166_2,]
})
output$leafplot1 <- renderLeaflet({
leaflet(unfilteredData1(), options = leafletOptions(crs = epsg2163)) %>%
addPolygons(weight = 1, color = "#444444", opacity = 1,
fillColor = ~pal(pop_2014), fillOpacity = 0.7, smoothFactor = 0.5,
label = ~paste(name, pop_2014),
labelOptions = labelOptions(direction = "auto"))
})
output$leafplot2 <- renderLeaflet({
leaflet(filteredData2(), options = leafletOptions(crs = epsg2163)) %>%
addPolygons(weight = 1, color = "#444444", opacity = 1,
fillColor = ~pal(pop_2014), fillOpacity = 0.7, smoothFactor = 0.5,
label = ~paste(name, pop_2014),
labelOptions = labelOptions(direction = "auto"))
})
}
# Run the application
shinyApp(ui = ui, server = server)