I have a Shiny app that uses parallel::mclapply
to run a simulation many times in parallel, then gathers all results and summarizes them. The app works fine on my local machine, but after deploying it to Shinyapps.io, it immediately fails when I hit my actionButton. The log gives a clue:
Warning in parallel::mclapply(1:input$simrep_count, function(i) { : all scheduled cores encountered errors in user code
Is there something that prevents using mclapply
within shinyapps.io? Or am I just missing something?
FYI the app works fine with lapply
instead of mclapply
so I assume it's a parallelization issue.
The documentation warns the use within shinyapps has only be tested on MacOS so maybe not compatible with Shiny running on Ubuntu servers.
Warning
It is strongly discouraged to use these functions in GUI or embedded environments, because it leads to several processes sharing the same GUI which will likely cause chaos (and possibly crashes). Child processes should never use on-screen graphics devices. Some precautions have been taken to make this usable in R.app
on macOS, but users of third-party front-ends should consult their documentation. Note that tcltk counts as a GUI for these purposes since Tcl
runs an event loop. That event loop is inhibited in a child process but there could still be problems with Tk graphical connections.
Thanks @andresrcs , what documentation are you referring to?
parallel::mclapply()
documentation