Error when deploying R Shiny app: Error: C stack usage 7969860 is too close to the limit

I've been reading other people having similar issues when deploying shinyapp to https://www.shinyapps.io

The common issue appears to be the used packages by the app, and the solution is to install them from CRAN instead of Github. I've done this but without success.

I'm thinking it's because I'm using the leaflet package to show a map. It was a little difficult to have it running locally and maybe it's more difficult for https://www.shinyapps.io to deploy it?

This is my APP, maybe someone could help me out:

ui.R:

library(shiny)
library(shinydashboard)
library(plotly)
library(formattable)
library(DT)
library(leaflet)
library(plotly)






header <- dashboardHeader(title = 'LaCuracao.pe Dashboard',
                          tags$li(class = "dropdown",
                                  tags$a(href="https://lacuracao.pe/", target="_blank", 
                                         tags$img(height = "22px", alt="La Curcao Perú", src="lc-logo.png")
                                  )
                          )
)




sidebar <- dashboardSidebar(
  sidebarMenu(
    menuItem("Ventas", tabName = "Ventas", icon = icon("th"),
             badgeLabel = "new", badgeColor = "green"),
    menuItem("ga", tabName = "ga", icon = icon("th"),
             badgeLabel = "new", badgeColor = "green"),
    menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
  )
)



body <- dashboardBody(
  tabItems(
    tabItem(tabName = "resumen",
            fluidRow(
              box(width = 2, actionButton("count", "Count")),
              infoBoxOutput("ibox"),
              valueBoxOutput("vbox")
            )
            
    ),
    tabItem(tabName = "dashboard",
            dateRangeInput('dateRange',
                           label = 'Seleccione fechas',
                           start = '2018-05-01', end = '2018-05-31',
                           language = 'es', separator = " al "),
            column(6

            ),
            DT::dataTableOutput('productos_ingresos'),
            br(),
            br()
            
    ),
    tabItem(tabName = "ga",
            column(6
            ),
            
            DT::dataTableOutput('sesiones_por_mes'),
            plotlyOutput("plot"),
            br()
            
    ),
    tabItem(tabName = "Ventas",
            h2("Ventas Perú"),
            #verbatimTextOutput("total_ventas"),
            
            radioButtons("lima_no_lima", "Total departamentos a visualizar:",
                         inline = TRUE,
                         choices = c("Considerar Lima" = "considerar_lima",
                                      "No considerar Lima" = "no_considerar_lima")),
            dateRangeInput('dateRangeMap',
                           label = 'Seleccione fechas',
                           start = '2018-08-01', end = '2018-08-16',
                           min    = "2018-08-01",
                           max    = "2020-08-21",
                           language = 'es', separator = " al "),
            textOutput("total_ventas"),
            leafletOutput("mymap"),
            br(),
            br()
    )
  )
)



# Put them together into a dashboardPage
dashboardPage(skin = "black",
  header,
  sidebar,
  body
)

server.R



library(shiny)
library(leaflet)
library(dplyr)
library(readr)
library(plotly)

server <- function(input, output, session) { #session is an important argument for server function 
  
  peru_ventas <- reactive({ 
      
    
    
    #ventas <- read_csv("www/ventas.csv", skip = 2)
    ventas <- read_csv("https://www.dropbox.com/s/ehzwrjnwkwbs06p/ventas.csv?dl=1", skip = 2)
    
    ventas <- ventas[,c("FECHA_PED", "DEPARTAMENTO", "TOTAL_PEDIDO")]
    
    
    
    ventas$TOTAL_PEDIDO <- as.numeric(ventas$TOTAL_PEDIDO)
    
    
    
    ventas$FECHA_PED <- as.Date(ventas$FECHA_PED, format = "%d/%m/%Y")
    
    
    ventas$DEPARTAMENTO <- gsub("CALLAO", "LIMA", ventas$DEPARTAMENTO)
    
    
    
 
    
    
    
    dates <- seq(as.Date(input$dateRangeMap[1]), as.Date(input$dateRangeMap[2]), "days")
    
    
    
  
    
    
    if(input$lima_no_lima == "considerar_lima") {
      print("Se considera Lima")
      
      ventas_departamentos <- ventas %>%
        group_by(DEPARTAMENTO) %>%
        summarise(VENTAS = sum(TOTAL_PEDIDO * (FECHA_PED %in% dates),
                               na.rm = TRUE))
      
    } else if(input$lima_no_lima == "no_considerar_lima") {
      
      print("No se considera Lima")
      
      ventas_departamentos <- ventas %>%
                              group_by(DEPARTAMENTO) %>%
                              summarise(VENTAS = sum(TOTAL_PEDIDO * (FECHA_PED %in% dates),
                                                     na.rm = TRUE)) %>%
                              mutate(VENTAS = case_when(DEPARTAMENTO == "LIMA" ~ 0,
                                                        DEPARTAMENTO != "LIMA" ~ VENTAS))
    }
    
      
     
      
     
      peru <- geojsonio::geojson_read("https://www.dropbox.com/s/j8a0a9jecrcd8a2/peru_sin_callao.geojson?dl=1", what = "sp")
      
      
      peru$ventas <- ventas_departamentos$VENTAS
      
      peru
    
  })
  
### Sesiones GA ####
  
  
  sesiones <- reactive({ 
    
    

    sesiones_ga <- read_csv("https://www.dropbox.com/s/gvov9pgaxk125aa/ga-sesiones-lc-20180824.csv?dl=1", skip = 0)
    
    sesiones_ga <- sesiones_ga %>%
                  group_by(sources) %>%
                  summarise(sessions = sum(sessions))
    
    
    
  })
  
  
  
  
  productos <- reactive({ 
    
  

    productos_revenue <- read_csv("https://www.dropbox.com/s/75hmxn79k9zvlgk/ga-productos-lc-20180824.csv?dl=1", skip = 0)
    
  })
  
  
  output$productos_ingresos <- DT::renderDataTable(
    datatable(productos(),
              options = list(
                order = list(list(3, 'desc')),
                language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json'))) %>% formatCurrency(c('itemRevenue'), currency = ' S/.',
                                      interval = 3, mark = ',', before = TRUE) 
  )
  
  
####  
  
  
  
  output$sesiones_por_mes <- DT::renderDataTable(
    datatable(sesiones()) 
  )
  
#######  
  
  output$plot <- renderPlotly({
    plot_ly(sesiones(), x = ~sessions, y = ~sources, type = 'bar', orientation = 'h') %>% #color = I("red")
      layout(title = "Sesiones por fuente de tráfico",
             xaxis = list(title = ""),
             yaxis = list(title = "")) %>%
      layout(hovermode = 'compare',
             separators = ',')
  })


  
#######  
  
  
  
  
  

   output$total_ventas <- renderText({
     paste0("Total ventas: S/.", prettyNum(sum(peru_ventas()$ventas),big.mark=",", preserve.width="none"))
   })


  output$mymap <- renderLeaflet({
    #browser()
    peru <- peru_ventas()  
    
    pal <- colorBin("YlOrRd", domain = peru$ventas, bins = 5)
    
    
    labels <- sprintf(
      "<strong>%s</strong><br/>S/.%s soles",
      peru$NOMBDEP,  prettyNum(peru$ventas,big.mark=",", preserve.width="none")
    ) %>% lapply(htmltools::HTML)
    
   
    
    leaflet(peru) %>%
      setView(-75, -10, 4) %>%
      addProviderTiles("MapBox", options = providerTileOptions(
        id = "mapbox.light",
        accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN'))) %>%
      addPolygons(
        fillColor = ~pal(ventas),
        weight = 2,
        opacity = 1,
        color = "white",
        dashArray = "3",
        fillOpacity = 0.7,
        highlight = highlightOptions(
          weight = 3,
          color = "#666",
          dashArray = "",
          fillOpacity = 0.7,
          bringToFront = TRUE),
        label = labels,
        labelOptions = labelOptions(
          style = list("font-weight" = "normal", padding = "3px 8px"),
          textsize = "15px",
          direction = "auto")) %>%
      addLegend(pal = pal, values = ~ventas, opacity = 0.7, title = NULL,
                position = "bottomright")
    
  })
  
}

Could you please include the full error you are seeing?

Could you clarify if the error is occurring when you deploy the application, or after successfully deploying when you visit the application?

Hi Josh,

this error appears when trying to deploy to shinyapps.io

This is the full error:

Preparing to deploy application...DONE
Uploading bundle for application: 412884...Error: C stack usage  7970564 is too close to the limit
Ejecución interrumpida

In my dashboard my app appears as: status 'undeployed'.

But this link appears: shows 404 error.

https://omargonzalesdiaz.shinyapps.io/curacaoapp/

sessionInfo():

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=es_ES.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=es_ES.UTF-8        LC_COLLATE=es_ES.UTF-8    
 [5] LC_MONETARY=es_ES.UTF-8    LC_MESSAGES=es_ES.UTF-8   
 [7] LC_PAPER=es_ES.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] bindrcpp_0.2.2       readr_1.1.1          dplyr_0.7.6         
 [4] leaflet_2.0.2        DT_0.4               formattable_0.2.0.1 
 [7] plotly_4.8.0         ggplot2_3.0.0        shinydashboard_0.7.0
[10] shiny_1.1.0         

loaded via a namespace (and not attached):
 [1] httr_1.3.1             tidyr_0.8.1           
 [3] jsonlite_1.5           viridisLite_0.3.0     
 [5] assertthat_0.2.0       sp_1.3-1              
 [7] selectr_0.4-1          yaml_2.2.0            
 [9] progress_1.2.0         pillar_1.3.0          
[11] backports_1.1.2        lattice_0.20-35       
[13] glue_1.3.0             digest_0.6.16         
[15] RColorBrewer_1.1-2     promises_1.0.1        
[17] colorspace_1.3-2       htmltools_0.3.6       
[19] httpuv_1.4.5           plyr_1.8.4            
[21] pkgconfig_2.0.2        purrr_0.2.5           
[23] xtable_1.8-2           scales_1.0.0          
[25] later_0.7.3            tibble_1.4.2          
[27] withr_2.1.2            geojsonio_0.6.0.9100  
[29] ansistrings_1.0.0.9000 lazyeval_0.2.1        
[31] cli_1.0.0.9001         RJSONIO_1.3-0         
[33] magrittr_1.5           crayon_1.3.4          
[35] mime_0.5               maptools_0.9-3        
[37] evaluate_0.11          fansi_0.3.0           
[39] class_7.3-14           xml2_1.2.0            
[41] foreign_0.8-71         rsconnect_0.8.8       
[43] tools_3.4.4            data.table_1.11.4     
[45] prettyunits_1.0.2      hms_0.4.2             
[47] geojson_0.2.0          stringr_1.3.1         
[49] V8_1.5                 munsell_0.5.0         
[51] e1071_1.7-0            compiler_3.4.4        
[53] jqr_1.0.0              rlang_0.2.2           
[55] RCurl_1.95-4.11        units_0.6-0           
[57] classInt_0.2-3         grid_3.4.4            
[59] rstudioapi_0.7.0-9000  htmlwidgets_1.2       
[61] crosstalk_1.0.0        bitops_1.0-6          
[63] rmarkdown_1.10         gtable_0.2.0          
[65] DBI_1.0.0              curl_3.2              
[67] rematch2_2.0.1         R6_2.2.2              
[69] knitr_1.20             rgdal_1.3-4           
[71] rgeos_0.3-28           utf8_1.1.4            
[73] bindr_0.1.1            rprojroot_1.3-2       
[75] stringi_1.2.4          Rcpp_0.12.18          
[77] sf_0.6-3               spData_0.2.9.3        
[79] tidyselect_0.2.4
1 Like

This is an OS level error on your local machine.

Could you share exactly how you are triggering the deploy, i.e., from the console with rsconnect::deployApp() or via the publish button?

Could you try publishing with the rsconnect.error.trace option set to TRUE?

1 Like

Josh, the error appears either when deploying in the console or via publish button.

This is the result of

> options(rsconnect.error.trace = TRUE) 
> library(rsconnect)
> deployApp()
Preparing to deploy application...DONE
Uploading bundle for application: 412884...10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
9: tryCatchList(expr, classes, parentenv, handlers)
8: tryCatch({
       performPackratSnapshot(bundleDir)
   }, error = function(e) {
       e$msg <- paste0("----- Error snapshotting dependencies (Packrat) -----\n", 
           e$msg)
       if (isTRUE(getOption("rsconnect.error.trace"))) {
           traceback(3, sys.calls())
       }
       stop(e)
   })
7: addPackratSnapshot(appDir, implicit_dependencies)
6: snapshotDependencies(appDir, inferDependencies(appMode, hasParameters))
5: createAppManifest(bundleDir, appMode, contentCategory, hasParameters, 
       appPrimaryDoc, assetTypeName, users)
4: bundleApp(target$appName, appDir, appFiles, appPrimaryDoc, assetTypeName, 
       contentCategory, verbose)
3: force(code)
2: withStatus(paste0("Uploading bundle for ", assetTypeName, ": ", 
       application$id), {
       bundlePath <- bundleApp(target$appName, appDir, appFiles, 
           appPrimaryDoc, assetTypeName, contentCategory, verbose)
       if (isShinyapps(accountDetails)) {
           bundleSize <- file.info(bundlePath)$size
           checkSum <- digest::digest(bundlePath, "md5", file = TRUE)
           bundle <- client$createBundle(application$id, "application/x-tar", 
               bundleSize, checkSum)
           if (verbose) 
               timestampedLog("Starting upload now")
           if (!uploadBundle(bundle, bundleSize, bundlePath)) {
               stop("Could not upload file.")
           }
           if (verbose) 
               timestampedLog("Upload complete")
           response <- client$updateBundleStatus(bundle$id, status = "ready")
           bundle <- client$getBundle(bundle$id)
       }
       else {
           bundle <- client$uploadApplication(application$id, bundlePath)
       }
   })
1: deployApp()
Error: C stack usage  7971076 is too close to the limit
----- Deployment error -----
Error: C stack usage  7971076 is too close to the limit
----- Error stack trace -----
12: stop(e)
11: value[[3L]](cond)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
9: tryCatchList(expr, classes, parentenv, handlers)
8: tryCatch({
       performPackratSnapshot(bundleDir)
   }, error = function(e) {
       e$msg <- paste0("----- Error snapshotting dependencies (Packrat) -----\n", 
           e$msg)
       if (isTRUE(getOption("rsconnect.error.trace"))) {
           traceback(3, sys.calls())
       }
       stop(e)
   })
7: addPackratSnapshot(appDir, implicit_dependencies)
6: snapshotDependencies(appDir, inferDependencies(appMode, hasParameters))
5: createAppManifest(bundleDir, appMode, contentCategory, hasParameters, 
       appPrimaryDoc, assetTypeName, users)
4: bundleApp(target$appName, appDir, appFiles, appPrimaryDoc, assetTypeName, 
       contentCategory, verbose)
3: force(code)
2: withStatus(paste0("Uploading bundle for ", assetTypeName, ": ", 
       application$id), {
       bundlePath <- bundleApp(target$appName, appDir, appFiles, 
           appPrimaryDoc, assetTypeName, contentCategory, verbose)
       if (isShinyapps(accountDetails)) {
           bundleSize <- file.info(bundlePath)$size
           checkSum <- digest::digest(bundlePath, "md5", file = TRUE)
           bundle <- client$createBundle(application$id, "application/x-tar", 
               bundleSize, checkSum)
           if (verbose) 
               timestampedLog("Starting upload now")
           if (!uploadBundle(bundle, bundleSize, bundlePath)) {
               stop("Could not upload file.")
           }
           if (verbose) 
               timestampedLog("Upload complete")
           response <- client$updateBundleStatus(bundle$id, status = "ready")
           bundle <- client$getBundle(bundle$id)
       }
       else {
           bundle <- client$uploadApplication(application$id, bundlePath)
       }
   })
1: deployApp()

Here the results of appDependencies():

> rsconnect::appDependencies()
6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
5: tryCatchList(expr, classes, parentenv, handlers)
4: tryCatch({
       performPackratSnapshot(bundleDir)
   }, error = function(e) {
       e$msg <- paste0("----- Error snapshotting dependencies (Packrat) -----\n", 
           e$msg)
       if (isTRUE(getOption("rsconnect.error.trace"))) {
           traceback(3, sys.calls())
       }
       stop(e)
   })
3: addPackratSnapshot(appDir, implicit_dependencies)
2: snapshotDependencies(bundleDir)
1: rsconnect::appDependencies()
Error: C stack usage  7970852 is too close to the limit

How much memory does your local machine have?

How many files are there, recursively, in the directory from which you are deploying?

At this point we will likely have to loop in someone who develops the rsconnect package for further troubleshooting.

Josh, it was a problem only in Ubuntu. This machine has both Windows and Ubuntu and using Windows I could finally deploy my app :slight_smile:

1 Like