I have a large shapefile. For a better perfomance I try to load data with st_read()
from sf package
. The official documentation states that it should be very easy to integrate the shapefile into Leaflet/Shiny. Nevertheless, it does not work.
Error message: missing value where TRUE/FALSE needed
It works with rgdal
, but the performance is not that good. Link
I hope that someone can help me out.
small TestData
library(shiny)
library(leaflet)
library(sf)
shapefile <- st_read("pathToshape")
shinyApp(
ui <-fluidRow(
column(8,leafletOutput("map", height="600px"))
),
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(lng=16.357795000076294, lat=48.194883921677935, zoom = 15) %>%
addPolylines(data=shapefile, layerId = shapefile$id, group = shapefile$zeitver, color="red", weight=3,opacity=1)
})
})
st_read ()
shapefiles twice as fast. But as you explained, you can't handlesf
objects withinLeaflet()
. The perfomance in leaflet is actually quite good.