Open jiangwei221 opened 5 years ago
I am having an issue deploying a leaflet map using shiny, my choropleth map color is solid - no longer graduated (before adding in the shiny code it worked perfectly). Here is the code:
library(tigris) library(dplyr) library(leaflet) library(RColorBrewer) library(albersusa) library(sp) library(leaflet.extras) library(shiny) library(googlesheets)
options(tigris_use_cache = TRUE) states <- states(cb=T) turnout2<-gs_title("2018Midterm") turnout3 <- as.data.frame(turnout2)
states_turnout <- geo_join(states, turnout3, "NAME", "State")
library(RColorBrewer) mypalette = colorFactor( palette="Reds", domain=as.character(states_turnout$Ballots)) ee<- 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))
mid<- leaflet(usa_sf,options=leafletOptions(crs=ee))%>% setView(-98.483330, 38.712046, zoom = 3) %>% addResetMapButton()%>% addPolygons(data = states_turnout, fillColor = ~mypalette(states_turnout$Ballots), fillOpacity = 0.7, weight = 0.2, smoothFactor = 0.2, highlight = highlightOptions( weight = 3, color = "#666", fillOpacity = 0.7, bringToFront = TRUE), label=popup_turn, labelOptions = labelOptions( style = list("font-weight" = "normal", padding = "3px 8px"), textsize = "15px", direction = "auto"))
mid%>% setMapWidgetStyle(list(background="white"))
ui <- fluidPage( leafletOutput("midtermmap"), p() )
server <- function(input, output, session) {
output$midtermmap <- renderLeaflet({ mid%>% setMapWidgetStyle(list(background="white")) }) } shinyApp(ui, server)
Feel free to post questions as Issues.