Skip to content

Commit

Permalink
add colour choice #21
Browse files Browse the repository at this point in the history
  • Loading branch information
1234jc4321 committed Oct 17, 2016
1 parent f5b959a commit 21da247
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
36 changes: 18 additions & 18 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ shinyServer(function(input, output, session) {
show(id= "div_select_two")
show("pop_two_selected")
hide(id="div_select_one")


})

Expand All @@ -103,29 +103,29 @@ shinyServer(function(input, output, session) {
show('histPlot')
show("reload")
})

# Once group 1 and group 2 of cells are selected,
# create 10 boxplots showing the gene expression distributions
# of group 1 and group 2 for the top 10 up-regulated and
# top 10 down-regulated genes
output$histPlot <- renderPlotly({
if ( !is.null(differentiallyExpressed()) ) {
gene_cnt <- 10

nbr_group1 <- sum(selected_vector1())
nbr_group2 <- sum(selected_vector2())
nbr_barcodes <- nbr_group1 + nbr_group2

diff_genes <- differentiallyExpressed()$`Gene Symbol`
gene_idx <- c(1:gene_cnt, (length(diff_genes)-gene_cnt+1):length(diff_genes))

dg_mat <- c()
for ( n in gene_idx ) {
gene_idx <- which(genes$Symbol == diff_genes[n])
dat1 <- log2(expression[gene_idx, selected_vector1()] + 0.1)
dat2 <- log2(expression[gene_idx, selected_vector2()] + 0.1)
dg_mat <- rbind(dg_mat,

dg_mat <- rbind(dg_mat,
data.frame(gene = diff_genes[n],
expr = c(dat1, dat2),
group = c(rep("1", nbr_group1),
Expand All @@ -134,20 +134,20 @@ shinyServer(function(input, output, session) {
)
)
}

# dg_mat %>% mutate(
# gene = as.factor(gene),
# expr = as.numeric(expr),
# group = as.factor(group),
# panel = as.factor(panel)) %>%
dg_mat <-
dg_mat <-
dg_mat %>% mutate(
gene = as.character(gene),
expr = as.numeric(expr),
group = as.factor(group),
panel = as.factor(panel)) %>%
arrange(panel)

dg_mat$gene <- factor(dg_mat$gene, levels = dg_mat$gene)
ggplot(dg_mat, aes(x=group, y=expr, fill=group)) +
geom_boxplot() +
Expand All @@ -158,7 +158,7 @@ shinyServer(function(input, output, session) {
plotly_empty()
}
})

#output$newPlot <- renderPlotly({
# input$pop_selected
#new_tsne <- isolate(selected_data())
Expand Down Expand Up @@ -190,24 +190,24 @@ shinyServer(function(input, output, session) {
}
)
second_clicked <-reactive({input$pop_two_selected})





output$tSNE_summary <- renderPlotly({
second_clicked()
g1 = tsne[ tsne$barcode %in% barcodes$Barcode[isolate({selected_vector1()})],]
g2 = tsne[tsne$barcode %in% barcodes$Barcode[isolate({selected_vector2()})],]
g1["group"] <- rep('group 1', dim(g1)[1])
g2["group"] <- rep('group 2', dim(g2)[1])
both_groups = rbind(g1, g2)
plot_ly(both_groups, x = ~tSNE_1, y = ~tSNE_2, text = ~barcode, color = ~group, colors = c("dark blue", "dark red"),
plot_ly(both_groups, x = ~tSNE_1, y = ~tSNE_2, text = ~barcode, color = ~group, colors = c("dark blue", "dark red"),
key = ~barcode, source = "selection_plot_two") %>%
layout(dragmode = "select",xaxis = list(range = c(-40,40)),
yaxis = list(range = c(-40,40)))

})



output$downloadDifGenes = downloadHandler(
filename = 'difGenes.tsv',
Expand Down Expand Up @@ -290,7 +290,7 @@ shinyServer(function(input, output, session) {
output[[plotname]] <- renderPlotly({
gene_of_interest <- parse_gene_input(geneExpr_genes()[my_i])
gene_name <- parse_gene_input(geneExpr_genes()[my_i], get="name")
plot_geneExpr(gene_of_interest, gene_name, input_midplot=input$Midpoint)
plot_geneExpr(gene_of_interest, gene_name, input_midplot=input$Midpoint, color_low = input$colmin, color_mid = input$colmid, color_high = input$colmax)
})
})
}
Expand Down
10 changes: 6 additions & 4 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
library(shiny)
library(shinyjs)
library(plotly)

library(colourpicker)

# Define UI for application that draws a histogram
shinyUI(
Expand Down Expand Up @@ -48,8 +48,10 @@ shinyUI(
conditionalPanel(
condition = "input.checkVisualization == 1",
sliderInput("MinMax", label= h5("Range of expression:"), min = 0, max = 1, value = c(0,1), step= 0.02),
sliderInput("Midpoint", label= h5("Midpoint:"), min = 0, max = 1, value = 0.5, step= 0.02)
#numericInput("Midpoint", label = h3("Midpoint"), value = 1)
sliderInput("Midpoint", label= h5("Midpoint:"), min = 0, max = 1, value = 0.5, step= 0.02),
colourInput("colmin", "Select minimum colour", value = "grey"),
colourInput("colmid", "Select midpoint colour", value = "white"),
colourInput("colmax", "Select maximum colour", value = "red")
)
)

Expand All @@ -68,7 +70,7 @@ shinyUI(
column(8,
div(id= "div_select_one", plotlyOutput('tSNE_select_one')),
div(id = "div_select_two", plotlyOutput('tSNE_select_two')),
div(id= 'comparisonOutput', dataTableOutput('difGeneTable'),
div(id= 'comparisonOutput', dataTableOutput('difGeneTable'),
plotlyOutput('tSNE_summary'), plotlyOutput('histPlot'))
))
)
Expand Down

0 comments on commit 21da247

Please sign in to comment.