r - Shiny: "quantile" not working in reactive context -


i'm having problems using quantile take percentiles of user-specified variable in shiny app i'm writing, , using these percentile values set x limits histogram output.

i've tried bunch of fixes suggested in answers related questions keep getting different errors relating reactivity, variable type, , nas (even though have na.rm = true).

this example pared down more complex app can't show i've tried, i'm pretty sure problem happening in quantile command, , there may several different issues code. having trouble taking percentiles group_by_ , i'm not sure i've accounted nse.

here server file (problems in here):

  {if (!require("devtools"))   install.packages("devtools")   if (!require("ggplot2"))      install.packages("ggplot2")   if (!require("dplyr"))      install.packages("dplyr")   if (!require("lazyeval"))      install.packages("lazyeval") }   #load libraries  library(ggplot2)  library(dplyr)  library(lazyeval)  library(shiny)   #now server function shinyserver(function(input, output) {    #output histogram    output$histplot <- renderplot({     #make objects based on percentiles trim histogram see     lower.cut <- quantile(as.numeric(input$hist), probs = as.numeric(input$bottom), na.rm = true) #error: missing value true/false needed     upper.cut <- quantile(as.numeric(input$hist), probs = as.numeric(input$top), na.rm = true)     q <- ggplot(iris, aes_string(input$hist)) + geom_histogram(binwidth = (as.numeric(input$n_breaks))) +        coord_cartesian(xlim = c(lower.cut, upper.cut)) #i'm not sure whether or not working because can't past quantile commands     q       })    #output summary stats - among other things, output 95th, 98th, , 99th percentile values of selected histogram variable   output$summary <- renderprint({     w <- iris %>% group_by_(as.numeric(iris$species)) %>% summarize_(p95 = quantile(as.numeric(input$hist)), .95, na.rm=true) #error: missing values , nan's not allowed if 'na.rm' false   w    }) }) 

here ui file (this seems working fine):

{if (!require("devtools"))   install.packages("devtools")   if (!require("ggplot2"))      install.packages("ggplot2")   if (!require("dplyr"))      install.packages("dplyr")   if (!require("lazyeval"))      install.packages("lazyeval")   if (!require("psych"))      install.packages("psych") }  library(ggplot2)  library(dplyr)  library(lazyeval)  library(shiny)   shinyui(fluidpage(                         sidebarpanel( #this stuff in left side panel - user inputs , notes             h3("histogram"),     selectinput('hist', 'histogram variable', names(iris)),      numericinput('n_breaks', 'histogram bin width (type number, based on axis scale)', value = 10),     numericinput('bottom', 'histogram lower limit percentile (type number between 0 , 1, .01 = exclude bottom 1%)', value = 0), #default no bottom trim     numericinput('top', 'histogram upper limit percentile', value = 1), #default no top trim      hr()    ),    mainpanel( #this stuff in main body of page - make placeholder spots charts     fluidrow(       plotoutput("histplot"), #simple histogram        h4("summary statistics histogram variable (grouped species)"),       verbatimtextoutput("summary") #output summary statistics below   )) )) 

here errors receiving:

warning in quantile(as.numeric(input$hist), probs = as.numeric(input$bottom),  :   nas introduced coercion warning in quantile(as.numeric(input$hist), probs = as.numeric(input$top),  :   nas introduced coercion warning: error in if: missing value true/false needed stack trace (innermost first):     68: output$histplot      1: runapp warning: truncating vector length 1 warning in quantile(as.numeric(input$hist)) :   nas introduced coercion warning: error in quantile.default: missing values , nan's not allowed if 'na.rm' false stack trace (innermost first):     89: quantile.default     88: quantile     87: as.lazy_dots     86: lazyeval::all_dots     85: summarise_.tbl_df     84: summarize_     83: function_list[[k]]     82: withvisible     81: freduce     80: _fseq     79: eval     78: eval     77: withvisible     76: %>%     75: renderprint [r:\project\epar\working files\326 - changes in yield , crop allocation\r analysis\toy_app/server.r#32]     74: func     73: eval     72: eval     71: withvisible     70: evalvis     69: utils::capture.output     68: paste     67: output$summary      1: runapp 

here sessioninfo() output:

> sessioninfo() r version 3.2.4 revised (2016-03-16 r70336) platform: x86_64-w64-mingw32/x64 (64-bit) running under: windows 7 x64 (build 7601) service pack 1  locale: [1] lc_collate=english_united states.1252  lc_ctype=english_united states.1252    lc_monetary=english_united states.1252 lc_numeric=c                           [5] lc_time=english_united states.1252      attached base packages: [1] stats     graphics  grdevices utils     datasets  methods   base       other attached packages: [1] shinythemes_1.0.1 psych_1.6.6       lazyeval_0.2.0    dplyr_0.5.0       foreign_0.8-66    ggplot2_2.1.0     devtools_1.12.0   shiny_0.13.2       loaded via namespace (and not attached):  [1] rcpp_0.12.5      magrittr_1.5     mnormt_1.5-4     munsell_0.4.3    colorspace_1.2-6 xtable_1.8-2     r6_2.1.2         stringr_1.0.0    plyr_1.8.4       [10] tools_3.2.4      parallel_3.2.4   grid_3.2.4       gtable_0.2.0     dbi_0.4-1        withr_1.0.2      htmltools_0.3.5  digest_0.6.9     assertthat_0.1   [19] tibble_1.0       reshape2_1.4.1   memoise_1.0.0    mime_0.4         labeling_0.3     stringi_1.1.1    scales_0.4.0     jsonlite_0.9.22  httpuv_1.3.3  

names(iris) produces character vector in ui script. server script attempts find quantiles converting character vector numeric, converts names nas.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -