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.
library(shiny)
library(dplyr)
library(leaflet)
kenya_network <- sf::st_read("/vsicurl/https://github.com/OVI71397/Road-Maintenance/raw/main/data/kenya_roads/Kenya_roads_version2.shp")
kenya_bound <- sf::st_read("/vsicurl/https://github.com/OVI71397/Road-Maintenance/raw/main/data/Kenya_County_Boundaries/Kenya_County_Boundaries.shp")
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(
fluidRow(
shinycssloaders::withSpinner(
leaflet::leafletOutput('kenya_roads',
width = "100%",
height = 700),
size = 1, color = "#719b25")
)
)
server <- function(input, output, session){
output$kenya_roads <- renderLeaflet({
map
})
}
shinyApp(ui = ui, server = server)