mjwestgate / PredicTER

Shiny app for estimating the time needed to complete environmental systematic reviews or maps
4 stars 6 forks source link

Suggesting adding some sorting of lookup_dframe as the columns get mixed up otherwise #1

Closed DrMattG closed 4 years ago

DrMattG commented 4 years ago

Hey Martin, how are things? I am writing a grant application and wanted to make use of PredicTER but I was getting some very weird results (massive number of days and more articles than I started with!).

I fell in to the rabbit hole a bit but I think the issue is when the lookup_dframe is split.

Without sorting the resultant dataframe looks like this:

    # checked nperday percent
    # row2    14.6      10     854 # This is not percent but nperday (hence the weird results)
    # row3     192    25.0      10
    # row4   150.9     171       0
    # row5      10    21.4      44
    # row6   100.0    16.7       0
    # row7    11.7       0    76.0
    # row8   100.0       0     6.9
    # row9    59.2      24       0

With sorting the dataframe looks like this:

    # checked nperday percent
    # row2      10     854    14.6 # correct col order 
    # row3      10     192    25.0
    # row4       0     171   150.9
    # row5      10      44    21.4
    # row6       0    16.7   100.0
    # row7       0    11.7    76.0
    # row8       0     6.9   100.0
    # row9       0      24    59.2

I have changed this section in the server.R file:

calculate and plot summary values

observe({
    # look up relevant data using lapply
    x <- names(input)
    lookup_check <- grepl("^row[0-9]", x, perl=TRUE)
    lookup_names <- x[which(lookup_check)]
    lookup_dframe <- as.data.frame(
  do.call(rbind, strsplit(lookup_names, "_")),
  stringsAsFactors = FALSE
)
    colnames(lookup_dframe) <- c("row", "stage", "column")
    lookup_dframe$value <- unlist(lapply(lookup_names,
  function(a){input[[a]]}
))
    lookup_dframe<-lookup_dframe[order(lookup_dframe$row, lookup_dframe$column),] # This is the change I suggest

I hope that makes sense and that I haven't screwed up your code!

Matt