The shiny app disconnected from the server when attempting to display a leaflet object which uses a shape file.

I am trying to deploy my shiny app with AWS EC2 Server. My app processes heavy shapefile (around 120 Mb) so I chose the t2.medium instance (4 Gb memory, 2 CPU) and I host the only app there. The whole app works fine, but once it's supposed to display the leaflet object it disconnects from the server before even loading the map, however, I don't have such a problem when I run the script locally in RStudio. The logs file doesn't display any errors. I searched the internet to find out what might be the cause of the problem and it was recommended to make some adjustments in shiny-server.conf file, so I did:
app_init_timeout 3000;
app_idle_timeout 0;
http_keepalive_timeout 3000;
sockjs_heartbeat_delay 300;
Unfortunately, it didn't work. Then I tried to experiment and reduced the amount of data displayed on the map and it worked. So it seems I am facing either time or memory-related issues (I might be wrong). Could you please provide any suggestions on how can I tackle this problem? The problematic piece of code is below.


kenya_network <- sf::st_read("/vsicurl/")
kenya_bound <- sf::st_read("/vsicurl/")
map <- leaflet(kenya_network) %>% 
  addTiles() %>% 
  setView(36.906, 0.4, zoom = 6) %>%
  addPolygons(data = kenya_bound, color = "#F8F9FB",
              opacity = 0.3,
              fillColor = "#F8F9FB",
              fillOpacity = 0.8) %>%
  addPolylines(data = kenya_network, 
               weight = 3,
               opacity = 1)
ui <- fluidPage(
                             width = "100%",
                             height = 700), 
      size = 1, color = "#719b25")

server <- function(input, output, session){
  output$kenya_roads <- renderLeaflet({

shinyApp(ui = ui, server = server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.