R Brilliant addPolygons brochure (colors not displayed)

I hope you help me. I created a choropleth Map with Leaflet. I combined my (dataframe with countries and random score) and Shapefile with Polygon data. While it works, however, if I implement it in R-Shiny, the map is displayed, but without color. There are also no errors. Does anyone know why?

My code is:

ui <- fluidPage(
  leafletOutput("map")
)


shinyServer(function(input, output) {

output$map <- renderLeaflet({
    test_map
  })
})

global.R

tmp <- tempdir()

url <- "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip"

file <- basename(url)

download.file(url, file)

unzip(file, exdir = tmp)

world <- readOGR(dsn = tmp, layer = "ne_50m_admin_0_countries", encoding = "UTF-8")

data <- data.frame(Code = c("AR", "AU", "BE", "BR"),
             Score = c(0.01, -0.05, 0.15, -0.22))

world <- merge(world, data,
               by.x = "iso_a2",
               by.y = "Code",
               sort = FALSE)

pal <- colorNumeric(
  palette = "RdYlGn",
  domain = world$Score
)

test_map <- leaflet(data = world) %>%
            addTiles() %>% 
            addPolygons(fillColor = ~pal(Score), 
                        fillOpacity = 0.9, 
                        color = "#BDBDC3", 
                        weight = 1)
+2
source share
1 answer

I know this is an old question, and I'm not sure if this will help or not, but I believe that you had a similar problem that was just resolved.

Rstudio , - Rstudio , .

, - ( , ). - . , , , , - gsub(".{2}$","",your_colour_vector) ( ).

, , , , . , , . , - ? , , , , .

+1

Source: https://habr.com/ru/post/1672427/


All Articles