Code in Shiny and in R are executing differently.

I've placed testdata.RData and repro.R (the app) on Github

My data wrangling inside the Shiny App execution results in different data (and incorrect) compared to when run outside app. If you execute the app, you will see the following:

If you instead run the code in R, substituting the inputs with the same values like this, you get entirely different results.

testdata %>%
dplyr::filter(trt == trt_list[2]) %>%
dplyr::select(x = log2FoldChange, qx = padj, mylabel) -> x
testdata %>%
dplyr::filter(trt == trt_list[1]) %>%
dplyr::select(y = log2FoldChange, qy = padj, mylabel) -> y
plotdata <- dplyr::left_join(x, y, by = c("mylabel"))
plotdata %>% dplyr::mutate(x = ifelse(, 0, x),
y = ifelse(, 0, y),
qx = ifelse(, 1, qx),
qy = ifelse(, 1, qy)) %>%
dplyr::mutate(significance = ifelse(plotdata$qx <= .1 & plotdata$qy > .1, "X-Significant",
ifelse(plotdata$qx > .1 & plotdata$qy <= .1, "Y-Significant",
ifelse(plotdata$qx <= .1 & plotdata$qy <= .1, "Both-Significant", "Neither")))) %>%
dplyr::filter(significance != "Neither") -> plotdata
final <-$significance))

Answer is this and is correct:

R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/
LAPACK: /usr/lib/x86_64-linux-gnu/


attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] shinythemes_1.1.2 DT_0.5 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.2 readr_1.3.1 tidyr_0.8.3 tibble_2.1.1
[10] ggplot2_3.1.1 tidyverse_1.2.1 shiny_1.2.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 cellranger_1.1.0 pillar_1.3.1 compiler_3.6.0 later_0.8.0 plyr_1.8.4 tools_3.6.0 digest_0.6.18 lubridate_1.7.4
[10] jsonlite_1.6 nlme_3.1-139 gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.2 rlang_0.3.1 cli_1.1.0 rstudioapi_0.10 crosstalk_1.0.0
[19] yaml_2.2.0 haven_2.1.0 withr_2.1.2 xml2_1.2.0 httr_1.4.0 htmlwidgets_1.3 hms_0.4.2 generics_0.0.2 grid_3.6.0
[28] tidyselect_0.2.5 glue_1.3.0 R6_2.3.0 readxl_1.3.1 modelr_0.1.4 magrittr_1.5 backports_1.1.4 scales_1.0.0 promises_1.0.1
[37] htmltools_0.3.6 rvest_0.3.3 assertthat_0.2.1 mime_0.6 xtable_1.8-3 colorspace_1.4-1 httpuv_1.4.5.1 stringi_1.2.4 lazyeval_0.2.2
[46] munsell_0.5.0 broom_0.5.2 crayon_1.3.4

A helpful individual on Stack Overflow was able to tell me what I was doing wrong.
The value from input$adj.pvalue needed to be converted to numeric with as.numeric(input$adj.pvalue)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.