Search code examples
rshinyshiny-server

Function using ASReml package in Shiny


I'm using the shareware package ASReml within a shiny app. In order to create a model, I need to use the asreml() function. I first create the data named data1.

If I use the asreml function, It works fine : model<-asreml(fixed=TRAIT~TEMOIN,random=~PANEL,data=data1,na.method.X="include",na.method.Y="include") and model is created

The problem is that I want to create a lot of different models in order to choose the best one. The easiest way to do that for me is to create a function that return a list of models. For exemple, I did this : Model.list.creator=function(data.sle){ model<-asreml(fixed=TRAIT~TEMOIN,random=~PANEL,data=data.sle,na.method.X="include",na.method.Y="include") models=list(model) return(models) }

If I use the function in the R console with Results=Model.list.creator(data.sle=data1), I get the model using Results[[1]]. If I use the function within my shiny app, it returns me the error : Error in eval(expr, envir, enclos) : object 'data.sle' not found ... just after having diplayed the result of the function!!

NB : the calcul of mod is made in an observe loop.

Thanks in advance for any help on this problem


Solution

  • I found a solution on the VSNi forum - http://www.vsni.co.uk/forum/viewtopic.php?t=1081 Assigning formulas to the global environnment make them available even the asreml function is called within a function from a shiny app.