Skip to content

Commit

Permalink
Download buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
dsurujon committed Sep 25, 2019
1 parent dd40cf8 commit 9c71692
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 12 deletions.
81 changes: 75 additions & 6 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,49 @@ shinyServer(function(input, output) {
if(input$xaxis_log_single){
p=p+scale_x_log10()
}
values$plot_Panel1 <- p
return(p)
})

## PLOT DOWNLOADS (png, svg, pdf)
output$downloadPlot_Panel1_png <- downloadHandler(
filename = function() { paste(input$expt_single, '_Single_Expt.png', sep='') },
content = function(file) {
ggsave(file, plot = values$plot_Panel1, device = "png")
}
)
output$downloadPlot_Panel1_svg <- downloadHandler(
filename = function() { paste(input$expt_single, '_Single_Expt.svg', sep='') },
content = function(file) {
ggsave(file, plot = values$plot_Panel1, device = "svg")
}
)
output$downloadPlot_Panel1_pdf <- downloadHandler(
filename = function() { paste(input$expt_single, '_Single_Expt.pdf', sep='') },
content = function(file) {
ggsave(file, plot = values$plot_Panel1, device = "pdf")
}
)

# Table ouptut of selected genes
output$brushedTable_single <- renderDataTable({
df <- values$RNAdata_single
myaxis = selectedaxis_single()
df <- df[!is.na(df$log2FoldChange) & !is.na(df[myaxis]) &
df$Gene %in% values$geneselection_single,]

brushedPoints(df,input$plot1_brush, allRows=F, xvar = selectedaxis_single(), yvar="log2FoldChange")
values$RNAdata_single_DL <- brushedPoints(df,input$plot1_brush, allRows=F, xvar = selectedaxis_single(), yvar="log2FoldChange")
})

# download Panel1 Table
output$panel1download <- downloadHandler(
filename = function() {
paste0(input$expt_single,"_Single_Expt.csv")
},
content = function(file){
write.csv(values$RNAdata_single_DL, file)
}
)

#############
## Panel 2 ##
#############
Expand Down Expand Up @@ -166,20 +196,50 @@ shinyServer(function(input, output) {

colorvar <- input$color_plot2

ggplot(df, aes(x=log2FoldChange.x, y=log2FoldChange.y))+geom_point(alpha=0.3, aes_string(color=colorvar))+
p <- ggplot(df, aes(x=log2FoldChange.x, y=log2FoldChange.y))+geom_point(alpha=0.3, aes_string(color=colorvar))+
labs(x='DE- Experiment1',y='DE - Experiment2')+facet_grid(.~Time)+
theme_classic()

values$plot_Panel2 <- p
p

})
## PLOT DOWNLOADS (png, svg, pdf)
output$downloadPlot_Panel2_png <- downloadHandler(
filename = function() { paste0(input$expt1,"_",input$expt2, '.png') },
content = function(file) {
ggsave(file, plot = values$plot_Panel2, device = "png")
}
)
output$downloadPlot_Panel2_svg <- downloadHandler(
filename = function() { paste0(input$expt1,"_",input$expt2, '.svg') },
content = function(file) {
ggsave(file, plot = values$plot_Panel2, device = "svg")
}
)
output$downloadPlot_Panel2_pdf <- downloadHandler(
filename = function() { paste0(input$expt1,"_",input$expt2, '.pdf') },
content = function(file) {
ggsave(file, plot = values$plot_Panel2, device = "pdf")
}
)

# brushed table output
output$brushedTable_double <- renderDataTable({
df <- values$RNAdata_double
df <- df[!is.na(df$log2FoldChange.x) & !is.na(df$log2FoldChange.y) &
df$Gene %in% values$geneselection_double,]
brushedPoints(df,input$plot2_brush, allRows=F, xvar = "log2FoldChange.x", yvar="log2FoldChange.y")
values$RNAdata_double_DL <- brushedPoints(df,input$plot2_brush, allRows=F, xvar = "log2FoldChange.x", yvar="log2FoldChange.y")
})

# download Panel2 Table
output$panel2download <- downloadHandler(
filename = function() {
paste0(input$expt1,"_",input$expt2,"_Comparison.csv")
},
content = function(file){
write.csv(values$RNAdata_double_DL, file)
}
)

#############
## Panel 3 ##
Expand Down Expand Up @@ -433,6 +493,15 @@ shinyServer(function(input, output) {
myxaxis <- axisvars$xaxisvar
myyaxis <- axisvars$yaxisvar

brushedPoints(values$networkdf,input$networkstats_brush, allRows=F, xvar = myxaxis, yvar=myyaxis)
values$networkdf_DL <- brushedPoints(values$networkdf,input$networkstats_brush, allRows=F, xvar = myxaxis, yvar=myyaxis)
})
# Download table with network data
output$panel4download <- downloadHandler(
filename = function() {
paste0(input$network_experiment, "_",input$networkdatatime ,"_Network.csv")
},
content = function(file){
write.csv(values$networkdf_DL, file)
}
)
})
32 changes: 26 additions & 6 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ shinyUI(fluidPage(
checkboxInput('xaxis_log_single', 'log-scale x axis', FALSE),
sliderInput('alpha_single', 'Transparency', 0, 1, step=0.05, value=0.7)
), # /Column 1: plot options
column(width=9,
column(width=8,
tags$p("Scatter plot of DE (y-axis) of the selected experiments, against metadata variable (x-axis). \n Use the selectors above to change the experiment, or the metadata. \n Use the text box to paste a list of genes (one per line) to display only those genes."),
tags$p("Use the brush (draw a rectangle) on the plot to select genes. NOTE: BRUSH DOESN'T WORK WELL WHEN JITTER IS ON"),
plotOutput("TIGsingleplot",
brush = brushOpts(id = "plot1_brush") )
) # /column 2: plot
), # /column 2: plot
column(width=1,
downloadButton('downloadPlot_Panel1_png', 'Download Plot (png)'),
downloadButton('downloadPlot_Panel1_svg', 'Download Plot (svg)'),
downloadButton('downloadPlot_Panel1_pdf', 'Download Plot (pdf)')

)# /column 3: download buttons

), #/fluidRow for plots

fluidRow(
downloadButton('panel1download', 'Download Table')
), #/fluidRow for table DL

fluidRow(
dataTableOutput("brushedTable_single")

Expand All @@ -67,15 +77,23 @@ shinyUI(fluidPage(
textAreaInput('findgenes_double', 'Paste gene list - one gene per row',
value="")
), #column 1: plot options
column(width=9,
column(width=8,
tags$p('Scatter plot of DE from two experiments. Make sure the two experiments are from the same organism. \n Use the brush on the plot to select genes'),
plotOutput("TIGdoubleplot",
brush = brushOpts(id="plot2_brush")
)# plotOutput
) #column 2: plot
), #column 2: plot
column(width=1,
downloadButton('downloadPlot_Panel2_png', 'Download Plot (png)'),
downloadButton('downloadPlot_Panel2_svg', 'Download Plot (svg)'),
downloadButton('downloadPlot_Panel2_pdf', 'Download Plot (pdf)')

)# /column 3: download buttons

), # fluidrow for plots

fluidRow(
downloadButton('panel2download', 'Download Table')
), #/fluidRow for table DL
fluidRow(
dataTableOutput("brushedTable_double")
)
Expand Down Expand Up @@ -140,7 +158,9 @@ shinyUI(fluidPage(
)

),#/fluidRow

fluidRow(
downloadButton('panel4download', 'Download Table')
), #/fluidRow for table DL
fluidRow(
dataTableOutput("brushedTable_netstats")

Expand Down

0 comments on commit 9c71692

Please sign in to comment.