Error in value[[3L]](cond) : Timeout was reached:

I get this error about one out of four times with with my app on shinyapps. The rest of the time it runs normally. Anyone know what causes this/how to fix it? I never had any issues running it locally.
Complete error and code below:


The following objects are masked from ‘package:shiny’:

    dataTableOutput, renderDataTable


Attaching package: ‘shinydashboard’

The following object is masked from ‘package:graphics’:

    box

── Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.1.0       ✔ purrr   0.3.0  
✔ tibble  2.0.1       ✔ dplyr   0.8.0.1
✔ tidyr   0.8.2       ✔ stringr 1.4.0  
✔ readr   1.3.1       ✔ forcats 0.4.0  
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()

Attaching package: ‘jsonlite’

The following object is masked from ‘package:purrr’:

    flatten

The following object is masked from ‘package:shiny’:

    validate

Error in value[[3L]](cond) : 
  Timeout was reached: Connection timed out after 10000 milliseconds
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

My app is a map using data from an api.
Code:

library(DT)
library(leaflet)
library(shinydashboard)
library(googlesheets)
library(tidyverse)
library(htmltools)
library(jsonlite)

Boko = "https://api.acleddata.com/acled/read?terms=accept&actor2=Boko:OR:actor1=Boko&limit=2500&fields=event_date|event_type|actor1|assoc_actor_1|inter1|actor2|assoc_actor_2|interaction|country|admin1|admin2|admin3|location|latitude|longitude|source|source_scale|notes|fatalities"
IS="https://api.acleddata.com/acled/read?terms=accept&actor2=Barnawi:OR:actor1=Barnawi&limit=2500&fields=event_date|event_type|actor1|assoc_actor_1|inter1|actor2|assoc_actor_2|interaction|country|admin1|admin2|admin3|location|latitude|longitude|source|source_scale|notes|fatalities"
Ethnic="https://api.acleddata.com/acled/read?terms=accept&iso=120:OR:iso=148:OR:iso=562:OR:iso=566&inter1=4&limit=2000&fields=event_date|event_type|actor1|assoc_actor_1|inter1|actor2|assoc_actor_2|interaction|country|admin1|admin2|admin3|location|latitude|longitude|source|source_scale|notes|fatalities&year=2019:OR:year=2018:OR:year=2017:OR:year=2016:OR:year=2015"
Mil="https://api.acleddata.com/acled/read?terms=accept&iso=120:OR:iso=148:OR:iso=562:OR:iso=566&interaction=17&limit=1500&fields=event_date|event_type|actor1|assoc_actor_1|inter1|actor2|assoc_actor_2|interaction|country|admin1|admin2|admin3|location|latitude|longitude|source|source_scale|notes|fatalities&year=2019:OR:year=2018:OR:year=2017:OR:year=2016:OR:year=2015"
#Other

Boko <- fromJSON(Boko)
Boko <- as.data.frame(Boko)
Boko$Actor="Boko Haram"

Boko<-Boko[!(Boko$data.actor1=="Boko Haram - Wilayat Gharb Ifriqiyyah (Barnawi Faction)" | Boko$data.actor2=="Boko Haram - Wilayat Gharb Ifriqiyyah (Barnawi Faction)"),]

IS <- fromJSON(IS)
IS <- as.data.frame(IS)
IS$Actor="ISIS-WA"
Ethnic <- fromJSON(Ethnic)
Ethnic <- as.data.frame(Ethnic)
Ethnic$Actor="Ethnic Conflict"
Mil <- fromJSON(Mil)
Mil <- as.data.frame(Mil)
Mil$Actor="Military vs Civilian"


acled <- bind_rows(IS, Boko, Ethnic, Mil)
acled$data.latitude<-as.numeric(acled$data.latitude)
acled$data.longitude<-as.numeric(acled$data.longitude)
acled$data.fatalities<-as.numeric(acled$data.fatalities)
acled$RowCreated <- Sys.time()
data_date<-max(as.Date(acled$data.event_date))

# ui object
ui <- 
  navbarPage("Lake Chad Conflict",
             theme = "bootstrap.css",
             
             tabPanel("Map",
                      div(class="outer",
                          
                          leafletOutput("map", width = "100%", height = "100%"), #
                          absolutePanel(
                            id = "controls", 
                            class = "panel panel-default",
                                        fixed = TRUE, width = 250, 
                                        draggable = TRUE, top = "10%", 
                                        left = "auto", right = 20, bottom = "auto",
                                        height = "auto", cursor = "move",
                                        sliderInput("slider", "Time Range", min = as.Date("2015-01-01"),max =as.Date(Sys.Date()),value=c(as.Date("2018-01-01"), as.Date(Sys.Date())),timeFormat="%b %Y"),
                                        textOutput("SliderText"),
                                        tags$small( "Source:", tags$a( href="https://acleddata.com", "ACLED"), "updated: ",as.character(data_date, format="%B %d %Y")),
                                        br()
                          )
                          
                      )
             ),
             
             tabPanel("Table",
                      div(class="outer", style='height:95%; overflow-y: scroll',  
                          h3("Tables"),
                          DTOutput(outputId = "table")
                      )
            
                       ),
             navbarMenu("More",
                        tabPanel( a("Liptako Conflict Map", href="https://otiweb.ml/sahel-conflict")
                        ))
             
             )

# server()
server <- function(input, output){
  
  
  
  acled$data.event_date<-as.Date(acled$data.event_date)
  
  filtered_data <- reactive({
    acled[acled$data.event_date >= input$slider[1] & acled$data.event_date <= input$slider[2],]
  })
  
  
  output$table <- renderDT(filtered_data(), options = list(scrollX = TRUE))
  output$map <- renderLeaflet({
    
    # Custom legend
    colors <- c("gray", "gray", "gray")
    labels <- c("No fatalities", "1-25 fatalities", "> 25 fatalities")
    sizes <- c(22, 22, 22)
    shapes <- c("circle", "circle", "circle")
    borders <- c("8px solid white", "4px solid white", "0px solid gray")
    addLegendCustom <- function(map, colors, labels, sizes, shapes, borders, opacity = 0.5){
      
      make_shapes <- function(colors, sizes, borders, shapes) {
        shapes <- gsub("circle", "50%", shapes)
        # shapes <- gsub("square", "0%", shapes)
        paste0(colors, "; width:", sizes, "px; height:", sizes, "px; border: ", borders, "; border-radius:", shapes)
      }
      make_labels <- function(sizes, labels) {
        paste0("<div style='display: inline-block;height: ", 
               sizes, "px;margin-top: 4px;line-height: ", 
               sizes, "px;'>", labels, "</div>")
      }
      
      legend_colors <- make_shapes(colors, sizes, borders, shapes)
      legend_labels <- make_labels(sizes, labels)
      
      return(addLegend(map, colors = legend_colors, labels = legend_labels, opacity = opacity, "bottomleft", title = "Fatalities"))
    }
    
    # Create leaflet
    
    factpal <- colorFactor(rainbow (5), acled$Actor)
    labs <- lapply(seq(nrow(filtered_data())), function(i) {
      paste0(  
        filtered_data()[i, "data.location"], ', ',
        filtered_data()[i, "data.admin1"], '<br> ',
        filtered_data()[i, "data.event_date"], '<br> ', 
        filtered_data()[i, "data.event_type"], '<br> ', 
        filtered_data()[i, "data.actor1"], ', vs. <br>', 
        filtered_data()[i, "data.actor2"],'<br>', 
        filtered_data()[i, "data.fatalities"], ' dead  ' ) 
    })
    
    
    
    l <- leaflet(data = acled) %>% addProviderTiles(providers$CartoDB.Positron) %>% 
      
      setView( lng = 13.5
               , lat = 12.5
               , zoom = 7 ) %>%
      setMaxBounds( lng1 = 11
                    , lat1 = 11
                    , lng2 = 16
                    , lat2 = 14 )   %>%
      
      
      addCircleMarkers(data=filtered_data(),  lng = ~data.longitude, lat = ~data.latitude, weight = 1,
                       radius = ~data.fatalities^0.3*3+2, color = ~factpal(Actor), 
                       label = lapply(labs, HTML), 
                       fillOpacity = 0.3,
                       labelOptions = labelOptions(
                         offset = c(-100,-140),
                         #direction='bottom',
                         textOnly = T,
                         style=list(
                           'background'='rgba(255,255,255,0.75)',
                           'border-color' = 'rgba(0,0,75,0.5)',
                           'border-radius' = '4px',
                           'border-style' = 'solid',
                           'border-width' = '1px'))#,
                       # highlightOptions = highlightOptions(weight = 3, bringToFront = TRUE)
                       
      ) %>%
      
      
      leaflet::addLegend("bottomleft", pal = factpal, values = ~acled$Actor, opacity = 0.7, title = "Conflict Type/Groups"
      ) %>%
      addLegendCustom(colors, labels, sizes, shapes, borders)
    
    
  })
}


shinyApp(ui = ui, server = server)```

I am nearly certain that error originates from issues with the API call. Does the data always need to be up to date? Because one option is to pre-download the data so you're calling it as a local file instead of an api call.

Thanks for the prompt reply. I could try running the API call once/day or a few times per week.

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.