r - Sum dataframe row values based on Shiny slider predicate -


i'm building shiny app reads in csv , displays 3 shiny datatables, each displayed in own tabpanel; i'm having trouble figuring out how handle third table.

the input csv contains values

0, 1, 2, 3, 4, 5 0.01, 0.02, 0.11, 0.00, 0.1 . . . 

i'm trying display table displays values, , additional column, tally's row values smaller slider predicate. if set slider value of 0.05 desired output be

tally, 0, 1, 2, 3, 4, 5 3, 0.01, 0.02, 0.11, 0.00, 0.1 

in ui.r i've tried (excluding non-relevant code)

sidebarpanel(         sliderinput("p-value", "p-value adjustment:",                     min = 0.01, max = 0.1, value = 0.05, step = 0.01),         ),  mainpanel(         #excluding 2 other panels work correctly          tabsetpanel(             tabpanel("interactive-data",                      datatableoutput("interactive.table"))           )      ) 

and in server.r

shinyserver(function(input, output) {    value.frame <- read.csv("path/to/file")     slidervalues <- reactive({      input.frame <- data.frame(         name = c("p-value"),         value = c(input$p-value))      data.frame(cbind(input.frame, value.frame, stringsasfactor=false))      })  #i'm lost here output$interactive.table = renderdatatable({     data.frame$tally <- rowsums(data.frame < p-value)     data.frame      }) 

i'm getting lost how use input sliderinput dynamically recalculate value of interactive.table$tally column. renderdatatable appropriate or there way go this?

this seems asking:

library(shiny) shinyui = pagewithsidebar(   headerpanel("title"),   sidebarpanel(     sliderinput("p.value", "p-value adjustment:",                 min = 0.01, max = 0.1, value = 0.05, step = 0.01)),   mainpanel(     tabsetpanel(       tabpanel("interactive-data",                datatableoutput("interactive.table")))) ) shinyserver = function(input,output){   value.frame <- data.frame(matrix(round(runif(60,0,0.2),2),ncol=6))   output$interactive.table <- renderdatatable({     tally <- sapply(1:nrow(value.frame), function(i)              rowsums(value.frame[i,2:ncol(value.frame)] < input$p.value,na.rm=t))     df <- data.frame("p-value"=input$p.value,tally,value.frame)     colnames(df)[3:8] <- c(as.character(0:5))     df   })} runapp(list(   ui = shinyui,   server = shinyserver )) 

there several problematic aspects of code. here few:

  1. referencing p-value rather input$p-value
  2. using p-value variable name. r thinks input$p-value input$p minus value. can around using input$"p-value" makes code unintelligible, changd p-value p.value.
  3. you reference data.frame in call renderdatatable(...) if variable.
  4. most of functions create or return data frames prepend x column names start number, if insist on numbers column names have rid of x's.
  5. rowsums(...) doesn't work way.

Comments