r - Validate() function for multiple conditions in Shiny, Rstudio -


i have wrote simplified version of code able give me direction go in. trying validate() process in shiny prevent function spc_macro running if fails. know can write multiple need clauses can make validate process fail independently need these clauses combined. example: below have validation clauses of mean=1, sigma=1, phase1=15, , userk=3.1. trying validate function return false sigma(which stop function running) if theses values set together. if user input mean=1, sigma=1, phase1=15 , userk=3.8 validate pass , function run. wondering if possible make multiple failing combinations. have run 3 simulations , these ones trying prevent being rerun user.

sim 1: mean=1, sigma=1, phase1=15, userk=3.1

sim 2: mean=2, sigma=2, phase1=30, userk=3.6

sim 3: mean=2, sigma=2, phase1=30, userk=4.0

`%then%` <- shiny:::`%or%` mean<-c(1,2,3) sd<-c(1,2,3) phase1<-c(15,20,25,30) k<-(c(3,3.2,3.4,3.6,3.8,4.0)) shinyserver(function(input, output) { output$mean <- renderui({   selectinput('mean', 'mean', mean) }) output$sigma<-renderui({    selectinput('sigma',"variation",sd) }) output$phase1<-renderui({   selectinput('phase1','phase1', phase1) }) output$userk<-renderui({   selectinput('userk','userk',k) })  rankuser<-eventreactive(input$gobutton, {   validate(     need(input$mean !="1","data exists")%then%     need(input$sigma !="1", "data exists")%then%     need(input$phase1!="15", "data extists")%then%     need(input$userk != "3.1", "data exists")   )   spc_macro(nphase1=input$phase1, nphase2=100000, varcount=1, meanshift=input$mean, sigmashift=input$sigma, k=input$userk, simid=100)   userdata<-rank_user_combined }) }) 

edit: tried @nice suggested doing:

rankuser<-eventreactive(input$gobutton, {     data_calculated<-list(val_data)      validate(       need(any(sapply(data_calculated,               function(x) identical(x,c(input$usernphase1,input$usermean,input$usersd,input$userk))),"data exists")     )     spc_macro(nphase1=input$usernphase1, nphase2=100000, varcount=1, meanshift=input$usermean, sigmashift=input$usersd, k=input$userk, simid=100)     userdata<-rank_user_combined   }) 

the structure of data_calculated looks like(the list has 400 rows total):

> data_calculated [[1]]     nphase1 meanshift sigmashift   k 1        10         4        1.0 3.0 2        15         0        1.0 3.0 3        15         0        1.0 3.1 4        15         0        1.0 3.2 5        15         0        1.0 3.3 6        15         0        1.0 3.4 7        15         0        1.0 3.5 8        15         0        1.0 3.6 9        15         0        1.0 3.7 10       15         0        1.0 3.8 

one solution make list of parameters have calculated data, ex:

#make list of vectors have calculated values data_calculated<-split(val_data,row.names(val_data)) data_calculated <- lapply(data_calculated,as.numeric) 

when user clicks go, can check whether parameters in list:

any(sapply(data_calculated,            function(x) identical(x,c(input$mean,input$sigma,input$phase1,input$userk))     )     ) 

the sapply loop through data_calculated , compare vector made of user inputs. any return true if identical vector found , false otherwise.

if wrap need should validate input.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -