Hi, goodnight. I have a problem when I render a leaflet polygon map, because is very slow to load it.
Is it possible to make it work faster somehow?
The data I use is the following: datacovid - Google Drive
And the code is:
library(readxl)
library(leaflet)
library(shiny)
library(echarts4r)
library(dplyr)
library(spdplyr)
library(lubridate)
library(tmap)
library(lubridate)
data("World")
datoscovid <- read_excel("/Users/jorge_hca/Desktop/Trabajo/datacovid.xlsx")
ui <- fluidPage(
dateInput("fecha", "Fecha a graficar:", value = "2021-02-12"),
leafletOutput("map")
)
server <- function(input, output){
datos <- reactive({
World |>
filter(continent == "North America" | continent == "South America") |>
select(name, geometry) |>
left_join(datoscovid, by = c("name" = "location")) |>
filter(date == input$fecha)
})
output$map <- renderLeaflet({
mypalette <- colorBin(palette="RdGy", domain=datos()$total_cases, na.color="transparent", bins = 4)
leaflet() %>%
addTiles("http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
attribution = paste(
"© <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors",
"© <a href=\"http://cartodb.com/attributions\">CartoDB</a>"
)) %>%
setView( lat=23, lng=-100 , zoom=3) %>%
addPolygons(
data = datos(),
fillColor = ~mypalette(total_cases),
stroke=TRUE,
fillOpacity = 0.85,
color="white",
weight=0.3,
label = mytext,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)
) %>%
addLegend(pal = mypalette, values = ~total_cases, opacity = 0.9, title = "Ingresos en México", position = "bottomleft", data = datos())
})
}
shinyApp(ui, server)
Thanks for reading me