problem with R package 'gbm' in Shiny app

624 views
Skip to first unread message

mfleo...@alaska.edu

unread,
May 29, 2013, 8:57:14 PM5/29/13
to shiny-...@googlegroups.com
Hi,

I am working on a Shiny app using gradient boosting, via the gbm package and am encounter a problem. I am simply trying to use the example code visible by looking up the gbm function, ?gbm. Specifically, running the example code to simulate the data and then create the object 'gbm1'. There is a discrepancy between running the example in an ordinary R session on my desktop vs. creating the same gbm object within a Shiny app.

It turns out, as long as the argument to gbm, 'cv.folds',  is set as cv.folds=1 (no cross-validation), it will work in Shiny. But if I set it to two or higher, the example still works fine in an ordinary R session but not within a Shiny app. I believe this is because the use of cross validation invokes some otherwise ignored nested functions within the gbm call which eventually invoke the base R 'parallel' package, in an attempt to detect multiple cores for sending different cross-validation folds to. This is visible by following the breadcrumb trail of the n.cores argument in the gbm function. It gets passed down through gbmCrossVal to gbmCrossValModelBuild to gbmCluster, where n.cores is finally used. However, I set n.cores=1 in the main gbm call to avoid any parallelization. But in any case, I get an error anytime cv.folds is greater than one., e.g. "2 nodes produced errors; first error: incorrect number of dimensions" where "2" is because I used cv.folds=2 this time.

I don't know if this is a Shiny problem, a gbm problem (in the sense that it works fine apart from Shiny but perhaps was not coded up in a way that will play nice with Shiny). Invariably when I see something like "incorrect number of dimensions" that is a clear indication it's probably user error and I have a typo somewhere. But in this case, it's the gbm package example code, and it runs fine when not built into a Shiny app. I apologize if this questions is a bit too esoteric for this venue. But hopefully whatever the problem is, it turns out to be a more general issue and doesn't have to do with gbm specifically, perhaps something with its attempted use of the parallel package, i.e. makeCluster and parLapply. 

Thanks,
Matt

Matthew Leonawicz

unread,
May 30, 2013, 6:35:37 PM5/30/13
to shiny-...@googlegroups.com
I have additional information if it is helpful.
Source code for the app as it currently stands:

I am using R 3.0.0, shiny 0.5.0, and most recent version of the gbm package, on Windows via local host. I have run it on a development server using shiny-server (development branch version) under otherwise same conditions, and I have the same problems there (our devel server not publicly visible, or I would send the link to the app).

Thanks,
Matt
Reply all
Reply to author
Forward
0 new messages