0

I am attempting to embed a choropleth graph using leaflet & shiny within a R Markdown document. The code worked fine as a chunk, but produces an error when ran altogether. Everything else in the R markdown file outputs fine, just not the leaflet map.

---
title: "COVID Testing Report"
author: "Name"
output: html_document
params:
  apikey: "970618602770bfaafac10ad533b4efa4973eb55b"
  state: "MD"
  county: "Baltimore City"
  popscale: "100000"
runtime: shiny
---

```{r echo = FALSE}
#interactive map for testing rate per 100k
ui <- fluidPage(
  leafletOutput("map", width = "100%", height = "100vh")
)

server <- function(input, output, session) {
  
  mypal <- colorNumeric(palette= "viridis", 10, domain = zip.data$testrate.all)
  
  output$map <- renderLeaflet({
    leaflet()%>%
      addProviderTiles("CartoDB.Positron")%>%
      addPolygons(
        data = zip.shp,
        fillColor = ~mypal(zip.data$testrate.all),
        stroke = TRUE,
        weight = 0.5,
        smoothFactor = 0.5,
        fillOpacity = .90,
        popup = paste("Test rate", zip.data$testrate.all, "<br>",
                      "Zipcode: ", zip.data$ZCTA5CE10, "<br>"))%>%
      addLegend(position = "bottomleft",
                pal = mypal,
                values = zip.data$testrate.all,
                title = paste0("Cumulative Test Rate\n", params$county, ", ", params$state),
                opacity = 1)
   
  })
  
}
shinyApp(ui, server)
```
Error: object 'params' not found
2
  • I would have expected object 'zip.data' not found first
    – r2evans
    Commented Jul 20, 2021 at 21:46
  • Resolved the error. Needed to 'setView': setView(lng = county.shp$INTPTLON,lat = county.shp$INTPTLAT, zoom = 10) Commented Jul 22, 2021 at 16:50

0

Browse other questions tagged or ask your own question.