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/')