|  |  | @ -45,7 +45,26 @@ ui <- fluidPage( | 
			
		
	
		
			
				
					|  |  |  | h3('Estadística'), | 
			
		
	
		
			
				
					|  |  |  | verbatimTextOutput('stats'), | 
			
		
	
		
			
				
					|  |  |  | tableOutput('tab_stats') | 
			
		
	
		
			
				
					|  |  |  | )) | 
			
		
	
		
			
				
					|  |  |  | )), | 
			
		
	
		
			
				
					|  |  |  | tabPanel("Exportar", | 
			
		
	
		
			
				
					|  |  |  | sidebarPanel(width=2, | 
			
		
	
		
			
				
					|  |  |  | h3('Seleccionar figura'), | 
			
		
	
		
			
				
					|  |  |  | selectInput("fig_id", "", selected="", choices=c("Cinética Grupo", "Cinética Individual", "Survival")), | 
			
		
	
		
			
				
					|  |  |  | h3('Formato'), | 
			
		
	
		
			
				
					|  |  |  | sliderInput("width", "Ancho", min=1000, max=20000, step=1000, value=10000), | 
			
		
	
		
			
				
					|  |  |  | sliderInput("height", "Altura", min=1000, max=20000, step=1000, value=6000), | 
			
		
	
		
			
				
					|  |  |  | textInput("colors", label="Colors", value=""), | 
			
		
	
		
			
				
					|  |  |  | sliderInput("errorbar-width", "% Ancho errorbars", min=0.05, max=1, step=0.05, value=0.05), | 
			
		
	
		
			
				
					|  |  |  | sliderInput("point-size", "Tamaño puntos", min=1, max=10, step=1, value=3), | 
			
		
	
		
			
				
					|  |  |  | sliderInput("font-size", "Tamaño textos", min=5, max=30, step=1, value=11), | 
			
		
	
		
			
				
					|  |  |  | checkboxInput(inputId = "legend", label = "Mostrar llegenda", value = T), | 
			
		
	
		
			
				
					|  |  |  | selectInput("theme", "Seleccionar Tema", selected="BW", choices=c("BW", "Default", "Classic")), | 
			
		
	
		
			
				
					|  |  |  | downloadButton("downloadPicture", "Exportar") | 
			
		
	
		
			
				
					|  |  |  | ), | 
			
		
	
		
			
				
					|  |  |  | mainPanel( | 
			
		
	
		
			
				
					|  |  |  | uiOutput("expPlotUI") | 
			
		
	
		
			
				
					|  |  |  | ) | 
			
		
	
		
			
				
					|  |  |  | ) | 
			
		
	
		
			
				
					|  |  |  | ) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | ) | 
			
		
	
	
		
			
				
					|  |  | @ -229,9 +248,12 @@ server <- function(input, output) { | 
			
		
	
		
			
				
					|  |  |  | if ("ID.tumor" %in% colnames(table)){table<-rename(table, "ID tumor"=`ID.tumor`)} | 
			
		
	
		
			
				
					|  |  |  | # table[table$ID.tumor == "R","0"]<-NA | 
			
		
	
		
			
				
					|  |  |  | col_nodays<-c("ID", "Cage","Group", "ID.animal","ID animal", "ID.tumor", "ID tumor", "TS","DPV", "Absorbance") | 
			
		
	
		
			
				
					|  |  |  | print(grep(0, colnames(table)[!colnames(table) %in% col_nodays])) | 
			
		
	
		
			
				
					|  |  |  | if (length(grep(0, colnames(table)[!colnames(table) %in% col_nodays])) == 0){ | 
			
		
	
		
			
				
					|  |  |  | table["0"]<-0 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | table<-melt(table, id=colnames(table)[colnames(table) %in% col_nodays], variable.name = "Timepoint") | 
			
		
	
		
			
				
					|  |  |  | table$Timepoint<-gsub("[A-Za-z ]","",table$Timepoint) | 
			
		
	
		
			
				
					|  |  |  | table$Timepoint<-factor(table$Timepoint, levels=mixedsort(as.numeric(as.character(unique(table$Timepoint))))) | 
			
		
	
		
			
				
					|  |  |  | if ("DPV" %in% colnames(table)){ | 
			
		
	
		
			
				
					|  |  |  | table<-dcast(table, Cage+`ID animal`+`ID tumor`+Group+Timepoint~DPV, value.var = "value") | 
			
		
	
		
			
				
					|  |  |  | table$Major<-table$Major/1000 | 
			
		
	
	
		
			
				
					|  |  | @ -244,6 +266,7 @@ server <- function(input, output) { | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | if (!"Volume" %in% colnames(table)){table<-rename(table, "Volume"=value)} | 
			
		
	
		
			
				
					|  |  |  | table<-table %>% filter(!is.na(Group)) | 
			
		
	
		
			
				
					|  |  |  | table$Timepoint<-factor(table$Timepoint, levels=mixedsort(as.numeric(as.character(unique(table$Timepoint))))) | 
			
		
	
		
			
				
					|  |  |  | analysis$taula_def<-table | 
			
		
	
		
			
				
					|  |  |  | table_plot<-dcast(dcast(table %>% filter(!is.na(Volume)), `ID animal`+Group+Timepoint~., value.var = "Volume", fun.aggregate = mean), Group~Timepoint) | 
			
		
	
		
			
				
					|  |  |  | table_plot | 
			
		
	
	
		
			
				
					|  |  | @ -373,6 +396,88 @@ server <- function(input, output) { | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | }) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | output$expPlotUI<- renderUI({ | 
			
		
	
		
			
				
					|  |  |  | observeEvent(analysis$taula_def, {}) | 
			
		
	
		
			
				
					|  |  |  | if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ | 
			
		
	
		
			
				
					|  |  |  | plotOutput("expPlot", width=paste0(input$width/10,"px"), height = paste0(input$height/10, "px")) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | }) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | output$expPlot <- renderPlot({ | 
			
		
	
		
			
				
					|  |  |  | observeEvent(analysis$taula_def, {}) | 
			
		
	
		
			
				
					|  |  |  | if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ | 
			
		
	
		
			
				
					|  |  |  | table<-analysis$taula_def | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | print(head(table)) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | if (input$fig_id == "Cinética Grupo"){ | 
			
		
	
		
			
				
					|  |  |  | if (input$vacc == "Sí"){ | 
			
		
	
		
			
				
					|  |  |  | g<-ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+ | 
			
		
	
		
			
				
					|  |  |  | scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+ | 
			
		
	
		
			
				
					|  |  |  | facet_grid(factor(`ID tumor`, labels = c("Vaccination", "Rechallenge"))~., scale="free_y")+ | 
			
		
	
		
			
				
					|  |  |  | theme_bw() | 
			
		
	
		
			
				
					|  |  |  | }else{ | 
			
		
	
		
			
				
					|  |  |  | g<-ggplot(table, aes(Timepoint, Volume, color=Group, group=Group))+ | 
			
		
	
		
			
				
					|  |  |  | theme_bw() | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | if (input$fig_id == "Cinética Individual"){ | 
			
		
	
		
			
				
					|  |  |  | if (input$vacc == "Sí"){ | 
			
		
	
		
			
				
					|  |  |  | g<-ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+ | 
			
		
	
		
			
				
					|  |  |  | scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+ | 
			
		
	
		
			
				
					|  |  |  | facet_grid(factor(`ID tumor`, labels = c("Vaccination", "Rechallenge"))~Group, scale="free_y")+ | 
			
		
	
		
			
				
					|  |  |  | theme_bw() | 
			
		
	
		
			
				
					|  |  |  | }else{ | 
			
		
	
		
			
				
					|  |  |  | g<-ggplot(table, aes(Timepoint, Volume, color=Group, group=`ID animal`))+ | 
			
		
	
		
			
				
					|  |  |  | facet_wrap(.~Group)+ | 
			
		
	
		
			
				
					|  |  |  | theme_bw() | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | g<-g+geom_errorbar(stat="summary", width=input$`errorbar-width`)+ | 
			
		
	
		
			
				
					|  |  |  | geom_line(stat="summary")+ | 
			
		
	
		
			
				
					|  |  |  | geom_point(stat="summary", size=input$`point-size`)+ | 
			
		
	
		
			
				
					|  |  |  | labs(x="Days after tumor challenge")+ | 
			
		
	
		
			
				
					|  |  |  | scale_y_continuous(expand = expansion(mult = c(0,0.05))) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | if (input$theme == "BW"){ | 
			
		
	
		
			
				
					|  |  |  | g<-g+theme_bw(base_size = input$`font-size`) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | if (input$theme == "Classic"){ | 
			
		
	
		
			
				
					|  |  |  | g<-g+theme_classic(base_size = input$`font-size`) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | if (input$theme == "Default"){ | 
			
		
	
		
			
				
					|  |  |  | g<-g+theme_gray(base_size = input$`font-size`) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | # g<-g+theme(axis.text.x=element_text(angle=45, hjust=1)) | 
			
		
	
		
			
				
					|  |  |  | if (input$legend == F){ | 
			
		
	
		
			
				
					|  |  |  | g<-g+guides(color=FALSE, fill=FALSE) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | if (input$colors != ""){ | 
			
		
	
		
			
				
					|  |  |  | v_col<-strsplit(input$colors, ",")[[1]] | 
			
		
	
		
			
				
					|  |  |  | g<-g+scale_color_manual(values=v_col)+ | 
			
		
	
		
			
				
					|  |  |  | scale_fill_manual(values=v_col) | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | dades$plot<<-g | 
			
		
	
		
			
				
					|  |  |  | g | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | }, res=72) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | output$downloadPicture <- downloadHandler( | 
			
		
	
		
			
				
					|  |  |  | filename = function() { | 
			
		
	
		
			
				
					|  |  |  | paste("Figura", ".png", sep="") | 
			
		
	
		
			
				
					|  |  |  | }, | 
			
		
	
		
			
				
					|  |  |  | content = function(file){ | 
			
		
	
		
			
				
					|  |  |  | print(file) | 
			
		
	
		
			
				
					|  |  |  | # tempReport <- file.path(tempdir(), "elispots.Rmd") | 
			
		
	
		
			
				
					|  |  |  | # file.copy("elispots.Rmd", tempReport, overwrite = TRUE) | 
			
		
	
		
			
				
					|  |  |  | png(file, width = input$width, height=input$height, units = "px", res=720) | 
			
		
	
		
			
				
					|  |  |  | plot(dades$plot) | 
			
		
	
		
			
				
					|  |  |  | dev.off() | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | }) | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
			
		
	
		
			
				
					|  |  |  | # Run the application |