From 1f6466168c0bd02a7a2717768b6f910794c4ec3f Mon Sep 17 00:00:00 2001 From: Andre Chalom Date: Tue, 7 Jun 2016 13:00:15 -0300 Subject: [PATCH] Adding pielou and interface no longer freezes on Rsampling::Rsampling error --- server.R | 16 +++++++++++----- ui.R | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/server.R b/server.R index a6e6b3b..1c0d017 100644 --- a/server.R +++ b/server.R @@ -121,6 +121,7 @@ shinyServer(function(input, output, session) { "azteca" = azteca, "peucetia" = peucetia, "rhyzophora" = rhyzophora, + "pielou" = pielou, "upload file" = csvfile()) }) ### calculates the distribution of the statistic of interest using Rsampling @@ -163,15 +164,18 @@ shinyServer(function(input, output, session) { vals$iter <- 1 vals$total_iterations <- input$ntrials vals$seqsim <- seq(100, vals$total_iterations, len=100) - vals$distribution <- Rsampling::Rsampling(type = type, dataframe = data(), + vals$distribution <- tryCatch( + Rsampling::Rsampling(type = type, dataframe = data(), statistics = statistic(), cols = cols(), stratum = isolate(stratum()), ntrials = isolate(input$ntrials), replace=isolate(input$replace), - progress = pupdate) + progress = pupdate), + error = function (e) 0) vals$maxcount<-max(hist(vals$distribution, plot=FALSE)$counts) }) - vals$run <- TRUE + if (length(vals$distribution) == vals$total_iterations) + vals$run <- TRUE # why is resume() called here??? run_iter$resume() }) @@ -225,12 +229,14 @@ shinyServer(function(input, output, session) { ### main plot of the program: generates a histogram of distribution() output$distPlot <- renderPlot({ # Traps errors + if(input$go != 0 && ! vals$run) { + plot(0,0, type='n',xlab="", ylab="", col.main="red", main=tr("Distribution calculation stopped with error!")); + return() + } if (input$go == 0 | !is.numeric(vals$x)) { plot(0,0, type='n',xlab="", ylab="", main=tr("Run the resampling to see the graphs")); return(); } - if (! vals$run) - stop(tr("Distribution calculation stopped with error!")) Rsampling::dplot(dist = vals$x, svalue = isolate(svalue()), pside= input$pside, extreme = input$extreme, vline = TRUE, rejection = input$rejection, ylim=c(0,vals$maxcount), main=tr("distplot_title"), xlab=tr("Statistic of interest"), ylab=tr("Frequency")) diff --git a/ui.R b/ui.R index fbe2d10..de15e67 100644 --- a/ui.R +++ b/ui.R @@ -150,7 +150,7 @@ shinyUI(fluidPage(theme= "bootstrap.css", helpText(tr("help1")), selectInput("datasource", tr("What is your input data?"), - choices = c("embauba", "azteca", "peucetia", "rhyzophora", "upload file") + choices = c("embauba", "azteca", "peucetia", "rhyzophora", "pielou", "upload file") ), ## the next panel only shows for the custom datasource fluidRow(column(6,conditionalPanel(