Hello. I'm developing an app that uses Stan for Bayesian fitting, but it won't let me run it in ShinyApps. I bought the basic plan, but it still wouldn't let me. Can anyone who's used Stan in ShinyApps help me?
Go to shinyapps.io click on your app in the table and then go to the Logs and paste what it shows. Also go to Settings and check that you're using the largest instance size available (which I think should be 8GB).
Now i'm in a free plan. But later, with de basic plan it doesn't run.
Here is the Log:
2025-04-15T15:58:08.439647+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.444277+00:00 shinyapps[14261463]: The following objects are masked from ‘package:stats’:
2025-04-15T15:58:08.450063+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.454939+00:00 shinyapps[14261463]: filter, lag
2025-04-15T15:58:08.459739+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.464549+00:00 shinyapps[14261463]: The following objects are masked from ‘package:base’:
2025-04-15T15:58:08.469596+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.474938+00:00 shinyapps[14261463]: intersect, setdiff, setequal, union
2025-04-15T15:58:08.480052+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.484922+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.489882+00:00 shinyapps[14261463]: Attaching package: ‘plotly’
2025-04-15T15:58:08.495845+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.500497+00:00 shinyapps[14261463]: The following object is masked from ‘package:ggplot2’:
2025-04-15T15:58:08.505277+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.510431+00:00 shinyapps[14261463]: last_plot
2025-04-15T15:58:08.515309+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.520106+00:00 shinyapps[14261463]: The following object is masked from ‘package:stats’:
2025-04-15T15:58:08.524921+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.529867+00:00 shinyapps[14261463]: filter
2025-04-15T15:58:08.535094+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.540494+00:00 shinyapps[14261463]: The following object is masked from ‘package:graphics’:
2025-04-15T15:58:08.545383+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.550316+00:00 shinyapps[14261463]: layout
2025-04-15T15:58:08.555260+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.560022+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.566538+00:00 shinyapps[14261463]: Attaching package: ‘DT’
2025-04-15T15:58:08.571722+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.577367+00:00 shinyapps[14261463]: The following objects are masked from ‘package:shiny’:
2025-04-15T15:58:08.582434+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.587592+00:00 shinyapps[14261463]: dataTableOutput, renderDataTable
2025-04-15T15:58:08.592873+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.597968+00:00 shinyapps[14261463]: Loading required package: StanHeaders
2025-04-15T15:58:08.602887+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.607689+00:00 shinyapps[14261463]: rstan version 2.32.7 (Stan version 2.32.2)
2025-04-15T15:58:08.612381+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.617674+00:00 shinyapps[14261463]: For execution on a local, multicore CPU with excess RAM we recommend calling
2025-04-15T15:58:08.622460+00:00 shinyapps[14261463]: options(mc.cores = parallel::detectCores()).
2025-04-15T15:58:08.627364+00:00 shinyapps[14261463]: To avoid recompilation of unchanged Stan programs, we recommend calling
2025-04-15T15:58:08.632253+00:00 shinyapps[14261463]: rstan_options(auto_write = TRUE)
2025-04-15T15:58:08.638962+00:00 shinyapps[14261463]: For within-chain threading using reduce_sum()
or map_rect()
Stan functions,
2025-04-15T15:58:08.643684+00:00 shinyapps[14261463]: change threads_per_chain
option:
2025-04-15T15:58:08.649035+00:00 shinyapps[14261463]: rstan_options(threads_per_chain = 1)
2025-04-15T15:58:08.653753+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.658553+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.663314+00:00 shinyapps[14261463]: Attaching package: ‘rstan’
2025-04-15T15:58:08.669649+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.674610+00:00 shinyapps[14261463]: The following object is masked from ‘package:tidyr’:
2025-04-15T15:58:08.679564+00:00 shinyapps[14261463]:
2025-04-15T15:58:08.684651+00:00 shinyapps[14261463]: extract
2025-04-15T15:58:08.689516+00:00 shinyapps[14261463]:
I just subscribed to the basic plan. I set the 8GB option in settings. When I run the app, I get the following:
An error has occurred
Unable to connect to worker after 60.00 seconds; startup took too long. Contact the author for more information.
I've never used Stan myself, but my colleagues use it and I remember them saying that it was complicated to deploy as the model has to be compiled when the app first runs. It sounds as if that might be what is taking > 60 seconds and why yours is failing to start? They use this github actions to precompile the model: MetaBayesDTA/.github/workflows/deploy.yaml at main · CRSU-Apps/MetaBayesDTA · GitHub If I remember correctly, it's related to shinyapps running on Ubuntu and the Stan models need to be compiled differently for different OSs. Maybe you can adapt that workflow to work for you?
I've got it now. It was just a matter of making some changes to the script so it would compile correctly. Thanks so much for your help.