0

My shiny app works fine in the console, but when I clean the R environment and runApp(), I get Error: C stack usage 15924528 is too close to the limit.

One related post suggests to type 'ulimit -s unlimited' in the terminal before starting R, however, I am running Rstudio from Windows so this does not work for me. Another posts states it might be caused by a recursive function that calls itself, and I think that is the problem here, but don't know how to solve it...

The getTGD() function from the gamlss package seems to give the error. I have made it reactive, otherwise it was stuck in infinite iterations (but again, only after runApp(), not in my console). However, even after making it reactive it seems to cause this error. Does anyone know how to solve this? Many thanks!

Below the Cstack info:

Cstack_info()

     size    current  direction eval_depth 
  15922790      23160          1          2 

And my R code:

library(shiny)
library(gamlss)

da <- readRDS(file="data/mydata.RDS")

gmod <- gamlss::gamlss(Outcome_transf ~cs(Age, by = Education_dich) + Education_dich, family= BE, data=da)


ui <- fluidPage(
  
  titlePanel('Title of app'),
  
  navbarPage("Choose a tab:",
             tabPanel("Title first tab",
                      sidebarLayout(
                        sidebarPanel(numericInput("Outcome", "Outcome measure", min = 15, max = 70, value = 70.00, step=0.01),
                                     numericInput("Age", "Age", min = 0, max = 110, value = 55, step=1),
                                     selectInput("Education_dich", "Educational level", choices = c('Low: Dutch Verhage scale 5 of lower'=0, 'Medium/High: Dutch Verhage scale 6 or 7'=1) )),
                        mainPanel(textOutput("txtOutput") )
                      ),
             ),
             
             
             tabPanel("Title second tab",
                      fluidRow( hr() ) ))
  )


server <- function(input, output, session) {

  
  output$txtOutput = renderText({ 

          input_df <- tryCatch(
            reactive({
            data.frame(Age = input$Age,
                       Education_dich = input$Education_dich,
                       Outcome_transf = input$Outcome/100 ) }),
              error = function(err){ cat('Error in input_df', err$message, '\n') })
    

                  NORM <- tryCatch(
                    reactive({getTGD(gmod, newdata=input_df())$resid}),
                    error = function(err) {
                      cat('Error with getTGD().', err$message, "\n") })
    
                  paste0("The norm score is: ", round(NORM(),2))
                  
    
  })
  

}



shinyApp(ui = ui, server = server)


rm(list = ls())
runApp('M:/users/stackoverflow/')
Meer
  • 1
  • 1
  • 1
    I've not found any situation where nesting `reactive` blocks made sense, it usually just confuses things (occasionally significantly). I've never seen somebody try triple-nesting. – r2evans Jul 27 '23 at 12:36
  • This error message typically means your have a recursive loop in your code. The recommendation for using "ulimit -s unlimited" is just not going to help. No matter the stack size you will exhaust it with a recursive loop. It's not clear what this code is supposed to do. It looks like you might be very new to shiny programming. Maybe checkout the basics of reactive programming from the shiny dev lectures: https://www.rstudio.com/resources/shiny-dev-con-2016/ – MrFlick Jul 27 '23 at 12:52
  • Thanks for the advise. I have fitted gmod, which predicts outcome based on certain variables. All I am trying to do here is to use gmod to predict the outcome based on new input variables, which can be defined in the app. I am using the getTGD function from the gamlss package to do this, but I think this functions might not work at all in Rshiny. Could someone please confirm this? – Meer Jul 28 '23 at 20:23

0 Answers0