Maximum call stack size exceeded only on chrome

3,695 views
Skip to first unread message

Ozgen Eren

unread,
Sep 21, 2018, 6:34:00 AM9/21/18
to Shiny - Web Framework for R
I have an analysis application that first checks if there were any previously done analysis and if there is, it reads it and shows it as a table. Otherwise user can run analysis himself and see the results in the same table. Everything works perfectly fine except I have a specific problem with chrome. 

Only when chrome is used (works in IE, safari, firefox), and there is a saved existing analysis result, Rshiny reads the file, I confirmed that it prepares the datatable correctly (~3000 rows) but does not show it (although I return the correct datatable to renderDataTable). However when I run the analysis, it is able to create the table and show it as it was supposed to using the same part of the code. So the problem is only apparent when the file is read from a file for the first time (although read is successfully completed and datatable was successfully prepared). And when I check the console I see "Maximum call stack size exceeded" error for that case. 

Could stack size be relevant with the datatable I am initially trying to show somehow? And would increasing the stacksize be a solution? If yes, how do I achieve that from R?

Ozgen Eren

unread,
Sep 21, 2018, 9:31:40 AM9/21/18
to Shiny - Web Framework for R
Exact error I am getting:

htmlwidgets.js:732 Uncaught RangeError: Maximum call stack size exceeded
    at Object.window.HTMLWidgets.evaluateStringMember (htmlwidgets.js:732)
    at exports.OutputBinding.shinyBinding.renderValue (htmlwidgets.js:496)
    at exports.OutputBinding.onValueChange (output_binding.js:16)
    at exports.OutputBinding.delegator.(:6158/anonymous function) [as onValueChange] (http://127.0.0.1:6158/htmlwidgets-1.2/htmlwidgets.js:112:23)
    at OutputBindingAdapter.onValueChange (output_binding_adapter.js:21)
    at ShinyApp.receiveOutput (shinyapp.js:354)
    at ShinyApp.<anonymous> (shinyapp.js:566)
    at ShinyApp._sendMessagesToHandlers (shinyapp.js:551)
    at ShinyApp.dispatchMessage (shinyapp.js:537)
    at WebSocket.c.onmessage (shinyapp.js:112)

Joe Cheng

unread,
Sep 21, 2018, 11:17:40 AM9/21/18
to Ozgen Eren, Shiny - Web Framework for R
It looks like you have some JS() options set in your data table? That error seems to be caused by infinite recursion trying to evaluate one of those.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/470b83e4-3c90-456e-898d-9d99fdc1d7cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ozgen Eren

unread,
Sep 21, 2018, 12:41:17 PM9/21/18
to Shiny - Web Framework for R
Yes you are right!

I tried removing few customizations and it turns out problem is caused by styling. 

% this part is okay
      result <- scanResultsOrdered %>% 
        datatable(
          selection = 'single',
          extensions = c('FixedColumns', 'Buttons'),
          rownames=FALSE,
          options=list(
            #dom = 't',
            dom = 'Bfrtip',
            scrollX=TRUE,
            buttons = c(I('colvis'),'copy', 'print'),
            fixedColumns = TRUE,
            columnDefs = list(list(visible=FALSE, targets=match(columns2hide, colnames(scanResultsOrdered))-1L ))
          ))

% this part fails in chrome
      result <- result %>% formatStyle(
          'Root',
          target = "row",
          backgroundColor = styleEqual(unlist(scanResultsOrdered[[1]]) , values=c(rep("red", nRed),rep("yellow", nYel),rep("white", nWhi)))
        )

What could be the problem here? 

Joe Cheng

unread,
Sep 21, 2018, 3:20:58 PM9/21/18
to Ozgen Eren, Shiny - Web Framework for R
If you could come up with a minimal reproducible example it would be a huge help.

Ozgen Eren

unread,
Sep 21, 2018, 6:59:05 PM9/21/18
to Shiny - Web Framework for R
Here is an example that gives the same problem on chrome but works on safari. 

require(shiny)
library(dplyr)
library(ggplot2)

ui <- fluidPage(
  titlePanel(title=h4("example", align="center")),
  mainPanel(
    DT::dataTableOutput('test')
  )
)

##server
server <- function(input, output){
  x<-tibble(a=c(1,2,3), color=c("red","yellow","white"))
  x<-tibble(a=1:(4*10^3), color=c(rep("red", 2*10^3), rep("yellow", 1*10^3), rep("white", 1*10^3) ))
  saveRDS(x,"./x.rds")
  
  output$test<-renderDataTable({
    data <- readRDS("./x.rds")
    result <- datatable(data,
              selection = 'single',
              rownames=FALSE,
              options=list(scrollX=TRUE)
              ) 
    
    result <- result %>% 
      formatStyle(
        'color',
        target = "row",
        backgroundColor = styleEqual(unlist(data[["color"]]) , values=c(rep("red", 2*10^3),rep("yellow", 1*10^3),rep("white", 1*10^3)))
      )
    return(result)
  })
}

shinyApp(ui = ui, server = server)

rahul kumar

unread,
Aug 19, 2020, 3:11:27 AM8/19/20
to Shiny - Web Framework for R
This error is almost always means you have a problem with recursion in JavaScript code, as there isn't any other way in JavaScript to consume lots of stack. Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as the memory that can be allocated for your use is not unlimited.
 
 Be considerate while calling functions , also dry run is the best practice to prevent them. It's possible to cause infinite recursion in a fully promisified code, too. That can happen if the promises in a chain don't actually perform any asynchronous execution , in which case control never really returns to the event loop, even though the code otherwise appears to be asynchronous. That's when it's useful to wrap your recursive function call into a -

  • setTimeout
  • setImmediate or
  • process.nextTick

In some programming languages this can be solved with tail call optimization, where the recursion call is transformed under the hood into a loop so no maximum stack size reached error exists. 
Reply all
Reply to author
Forward
0 new messages