diff --git a/app.R b/app.R index add3751..88edd49 100644 --- a/app.R +++ b/app.R @@ -131,14 +131,21 @@ server <- function(input, output) { t_maps<-generate_labstats(t_stats, t, "value", "variable", "Groups") dades$maps<<-t_maps } - print(t_substr) + if (length(unique(dades$taula[,"Groups"])) < 2){ + dades$stats<<-1 + } - dades$final<<-if(ctrl %in% colnames(t_substr)){t_substr %>% select(-cctrl)}else{t_substr} - # dades$final<<-if(ctrl %in% colnames(t_substr)){t_substr %>% select(-c(ctrl, mock))}else{t_substr %>% select(-mock)} + c(ctrl, mock)[c(ctrl, mock) %in% colnames(t_substr)] + dades$final<<-t_substr %>% select(-c(ctrl, mock)[c(ctrl, mock) %in% colnames(t_substr)]) set.seed(123) if (input$positive == T){ - ggplot(melt(t_substr, id=c("Mice", ctrl, "Groups")), aes(variable, value))+ + ids=c("Mice", "Groups", c(ctrl, mock)[c(ctrl, mock) %in% colnames(t_substr)]) + validate( + need(exists("mock_mean"), "No se puede elegir positividad con múltiples mocks") + ) + if (exists("mock_mean")){ + ggplot(melt(t_substr, id=ids), aes(variable, value))+ labs(x="", y="Spots/2.5*10^5 cells")+ # geom_errorbar(stat="summary", position=position_dodge(width=0.9), width=0.5, aes(fill=Groups))+ geom_hline(data=mock_mean, aes(color=Groups, yintercept = `.`))+ @@ -151,8 +158,10 @@ server <- function(input, output) { geom_text(data=t_stats, aes(t_maps$label$x, t_maps$label$y, label=p.signif), color="black")+ theme_bw()+ theme(axis.text.x=element_text(angle=45, hjust=1)) + } + }else{ - ids<-if(ctrl %in% colnames(t_substr)){c("Mice", ctrl, "Groups")}else{c("Mice", "Groups")} + ids=c("Mice", "Groups", c(ctrl, mock)[c(ctrl, mock) %in% colnames(t_substr)]) ggplot(melt(t_substr, id=ids), aes(variable, value))+ labs(x="", y="Spots/2.5*10^5 cells")+ # geom_errorbar(stat="summary", position=position_dodge(width=0.9), width=0.5, aes(fill=Groups))+ @@ -174,16 +183,22 @@ server <- function(input, output) { observeEvent(dades$stats, {}) t_stats<-dades$stats if (!is.null(dades$stats)){ - return( - t_stats %>% - flextable() %>% - theme_vanilla() %>% - fontsize(size=14, part="all") %>% - padding(padding=10, part="all") %>% - color(~ p.adj < 0.05, color = "red")%>% - autofit() - ) %>% - htmltools_value() + if (t_stats == 1){ + validate( + need(t_stats == 1, "Con un sólo grupo no se puede hacer estadística") + ) + }else{ + return( + t_stats %>% + flextable() %>% + theme_vanilla() %>% + fontsize(size=14, part="all") %>% + padding(padding=10, part="all") %>% + color(~ p.adj < 0.05, color = "red")%>% + autofit() + ) %>% + htmltools_value() + } } })