I want to create a r shiny dashboard using mapdeck package displaying the many layers of geojson in one map. But i have a problem, whenever I add styling into my geojson the R always crashes and nothing shown in my map. the memory also always high if i add a styling. But if i dont add any styling to my geojson data, the code works okay, but the display is just basic purple, i want to change the style according my clasification but it always crash. My data is not large, the "pwr.geojson" is only 600KB and the "point_sma.geojson" is only 30KB. I think it's because an infinite loop while rendering the style. Maybe anyone can answer what is wrong with the code or maybe another solution to stop the infinite loop?
here I provide the code:
library(shiny)
library(sf)
library(mapdeck)
#geojson for the main map
pwr <- sf::st_read("data/purworejo.geojson")
pointsma_pwr <- sf::st_read("data/point_sma.geojson")
ui <- dashboardPage(
dashboardHeader( #the header )
dashboardSidebar(#the sidebar )
dashboardBody(
tabItem(tabName = "viz",
fluidRow(
box(title = "Peta Preferensi Pemilih Pemula",
status = "primary",
width = 9,
height = "auto",
h2("Peta Preferensi Pemilih Pemula Pemilu 2024"),
mapdeckOutput("map", height = "800px")
)
)
)
)
)
server <- function(input, output) {
#access token mapbox
key <- "MAPBOX_ACCESS_TOKEN"
#rendering mapdeck
output$map <- renderMapdeck({
mapdeck(
token = key,
zoom = 10,
location = c(109.9989, -7.6965),
style = 'mapbox://styles/mapbox/light-v11'
) %>%
add_geojson(
data = pwr,
layer_id = "pwr-id",
update_view = F
) %>%
add_geojson(
data = pointsma_pwr,
layer_id = "pointsma-id",
update_view = F
)
})
}
shinyApp(ui = ui, server = server)
I try to add styling to the geojson for example like this
add_geojson(
data = pwr,
layer_id = "pwr-id",
update_view = F,
fill_colour = "green" #this is the styling i want to change
)
whenever i add the styling, the r always crashes, i expected the geojson will change the colour into green.
here I provide the console log:
Registered S3 method overwritten by 'jsonify':
method from
print.json jsonlite
it stops like that, and i supposed it's because of the infinite loop that happen while i add any styling. I also provide the memory change if i add the styling this is the increased memory if i ad the styling