Skip to content
This repository has been archived by the owner. It is now read-only.

Viewport #3

Merged
merged 26 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1c117fe
create_heatmap: param scale added (only working with static)
HendrikSchultheis Jan 10, 2018
67b2b75
create_heatmap: static -> scale legend fonts aswell
HendrikSchultheis Jan 10, 2018
8819a8f
create_heatmap: scale legend
HendrikSchultheis Jan 10, 2018
bc05d6c
create_heatmap: complexHeatmap row_dend_gp (not operational)
HendrikSchultheis Jan 10, 2018
d2a8a22
global_cor_heatmap: param scale added
HendrikSchultheis Jan 10, 2018
fbb0c00
global_cor_heatmap_example: scaleing slider
HendrikSchultheis Jan 10, 2018
df3abcb
manuals added
HendrikSchultheis Jan 10, 2018
8ede3c8
create_heatmap: now working scale with interactive plots
HendrikSchultheis Jan 12, 2018
04dbf0b
heatmap: support plot scaleing
HendrikSchultheis Jan 12, 2018
7976c0e
heatmap_example: use scaleing
HendrikSchultheis Jan 12, 2018
c7ed1ca
create_heatmap: scale texts aswell (interactive); create_geneView: im…
HendrikSchultheis Jan 12, 2018
88a85de
geneView: param scale added
HendrikSchultheis Jan 12, 2018
c62ab61
geneView_example: scale added
HendrikSchultheis Jan 12, 2018
fce6c61
create_pca: added param scale
HendrikSchultheis Jan 12, 2018
6452b22
pca: added parameter scale
HendrikSchultheis Jan 12, 2018
e2bfbc9
pca_example: scale slider added
HendrikSchultheis Jan 12, 2018
912d8f2
create_scatterplot: add param scale
HendrikSchultheis Jan 12, 2018
7511076
scatterPlot: scale param added
HendrikSchultheis Jan 12, 2018
5ae409a
scatterPlot_example: scale slider added
HendrikSchultheis Jan 12, 2018
35cf2c1
pca: clear plot on reset
HendrikSchultheis Jan 12, 2018
b8bbba5
geneView: clear plot on reset
HendrikSchultheis Jan 12, 2018
4d8fe8b
limit: fixed bug where ui wasn't reset
HendrikSchultheis Jan 12, 2018
9f71cb8
scatterPlot: hide plot on reset; fixed limit reset bug
HendrikSchultheis Jan 12, 2018
3a81ef2
heatmap: clear plot on reset
HendrikSchultheis Jan 12, 2018
c8da6c4
global_cor_heatmap: clear plot on reset
HendrikSchultheis Jan 12, 2018
948d851
Merge branch 'master' into viewport
HendrikSchultheis Jan 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 74 additions & 44 deletions R/function.R

Large diffs are not rendered by default.

56 changes: 37 additions & 19 deletions R/geneView.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ geneViewUI <- function(id, plot.columns = 3){
#' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param ppi Pixel per inch. Defaults to 72 and supports reactive.
#' @param scale Scale plot size. Defaults to 1, supports reactive.
#'
#' @details Width/ height/ ppi less or equal to default will use default value.
#' @details Ppi less or equal to zero will use default.
Expand All @@ -106,7 +107,7 @@ geneViewUI <- function(id, plot.columns = 3){
#'
#' @export

geneView <- function(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72){
geneView <- function(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72, scale = 1){
#handle reactive data
data.r <- shiny::reactive({
if(shiny::is.reactive(data)){
Expand Down Expand Up @@ -136,6 +137,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
width <- ifelse(shiny::is.reactive(width), width(), width)
height <- ifelse(shiny::is.reactive(height), height(), height)
ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi)
scale <- ifelse(shiny::is.reactive(scale), scale(), scale)

if(!is.numeric(width) || width <= 0) {
width <- "auto"
Expand All @@ -149,7 +151,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.

list(width = width,
height = height,
ppi = ppi)
ppi = ppi,
scale = scale)
})

#Fetch the reactive guide for this module
Expand All @@ -158,6 +161,10 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
rintrojs::introjs(session, options = list(steps = guide()))
})

# clear plot
clearPlot <- shiny::reactiveVal(FALSE)

# reset
shiny::observeEvent(input$reset, {
shinyjs::reset("genes")
shinyjs::reset("plotType")
Expand All @@ -170,6 +177,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
custom_label <<- shiny::callModule(label, "labeller", data = custom.label, sep = label.sep)
}
limiter <<- shiny::callModule(limit, "limit", lower = shiny::reactive(get_limits()[1]), upper = shiny::reactive(get_limits()[2]))
clearPlot(TRUE)
})

get_limits <- shiny::reactive({
Expand Down Expand Up @@ -255,6 +263,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
plot <- shiny::eventReactive(input$plot, {
# enable downloadButton
shinyjs::enable("download")
clearPlot(FALSE)

#new progress indicator
progress <- shiny::Progress$new()
Expand Down Expand Up @@ -282,7 +291,8 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.
plot.method = plot.method,
width = size()$width,
height = size()$height,
ppi = size()$ppi
ppi = size()$ppi,
scale = size()$scale
)

progress$set(1, detail = "Return plot")
Expand Down Expand Up @@ -327,30 +337,38 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot.

if(plot.method == "interactive") {
output$interactive <- plotly::renderPlotly({
#progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(message = "Rendering plot", value = 0)

plot <- plot()$plot

progress$set(value = 1)
return(plot)
})
} else if(plot.method == "static") {
output$static <- shiny::renderPlot(
width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)),
height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)),
{
if(clearPlot()) {
return()
} else {
#progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(message = "Rendering plot", value = 0.3)
progress$set(message = "Rendering plot", value = 0)

plot <- plot()$plot

progress$set(value = 1)
return(plot)
}
})
} else if(plot.method == "static") {
output$static <- shiny::renderPlot(
width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)),
height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)),
{
if(clearPlot()) {
return()
} else {
#progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(message = "Rendering plot", value = 0.3)

plot <- plot()$plot

progress$set(value = 1)
return(plot)
}
})
}

Expand Down
58 changes: 38 additions & 20 deletions R/global_cor_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ global_cor_heatmapUI <- function(id) {
#' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param ppi Pixel per inch. Defaults to 72 and supports reactive.
#' @param scale Scale plot size. Defaults to 1, supports reactive.
#'
#'
#'
#' @return Reactive containing data used for plotting.
#'
#' @export
global_cor_heatmap <- function(input, output, session, data, types, plot.method = "static", width = "auto", height = "auto", ppi = 72) {
global_cor_heatmap <- function(input, output, session, data, types, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) {
# load module -------------------------------------------------------------
# handle reactive data
data_r <- shiny::reactive({
Expand All @@ -180,6 +181,7 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
width <- ifelse(shiny::is.reactive(width), width(), width)
height <- ifelse(shiny::is.reactive(height), height(), height)
ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi)
scale <- ifelse(shiny::is.reactive(scale), scale(), scale)

if(!is.numeric(width) || width <= 0) {
width <- "auto"
Expand All @@ -197,7 +199,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method

list(width = width,
height = height,
ppi = ppi)
ppi = ppi,
scale = scale)
})

# load internal modules
Expand All @@ -217,6 +220,9 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
}

# functionality -----------------------------------------------------------
# clear plot
clearPlot <- shiny::reactiveVal(FALSE)

# reset ui
shiny::observeEvent(input$reset, {
shinyjs::reset("calc")
Expand All @@ -230,6 +236,7 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
columns <<- shiny::callModule(columnSelector, "select", type.columns = types, columnTypeLabel = "Column types to choose from")
transform <<- shiny::callModule(transformation, "transform", data = shiny::reactive(as.matrix(data_r()[, columns$selectedColumns(), with = FALSE])))
colorPicker <<- shiny::callModule(colorPicker2, "color", distribution = shiny::reactive(tolower(input$distribution)), winsorize = shiny::reactive(equalize(result_data()[, -1])))
clearPlot(TRUE)
})

# warning if plot size exceeds limits
Expand Down Expand Up @@ -308,6 +315,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
plot <- shiny::eventReactive(input$plot, {
# enable downloadButton
shinyjs::enable("download")
# show plot
clearPlot(FALSE)

# progress indicator
progress <- shiny::Progress$new()
Expand Down Expand Up @@ -346,7 +355,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
height = size()$height,
ppi = size()$ppi,
plot.method = plot.method,
winsorize.colors = colorPicker()$winsorize
winsorize.colors = colorPicker()$winsorize,
scale = size()$scale
)

# update progress indicator
Expand All @@ -361,34 +371,42 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method
width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)),
height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)),
{
if(clearPlot()) {
return()
} else {
# progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Rendering plot")

# get plot
plot <- plot()$plot

# update progress indicator
progress$set(1)

# draw plot
return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom"))
}
}
)
}else if(plot.method == "interactive") {
output$interactive <- plotly::renderPlotly({
if(clearPlot()) {
return()
} else {
# progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Rendering plot")

# get plot
plot <- plot()$plot

# update progress indicator
progress$set(1)

# draw plot
return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom"))
return(plot)
}
)
}else if(plot.method == "interactive") {
output$interactive <- plotly::renderPlotly({
# progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Rendering plot")

plot <- plot()$plot

# update progress indicator
progress$set(1)

return(plot)
})
}

Expand Down
51 changes: 34 additions & 17 deletions R/heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ heatmapUI <- function(id, row.label = TRUE) {
#' @param width Width of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param height Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.
#' @param ppi Pixel per inch. Defaults to 72 and supports reactive.
#' @param scale Scale plot size. Defaults to 1, supports reactive.
#'
#' @return Reactive containing data used for plotting.
#'
#' @export
heatmap <- function(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72) {
heatmap <- function(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", height = "auto", ppi = 72, scale = 1) {
# cluster limitation
static <- 11000
interactive <- 3000
Expand All @@ -125,6 +126,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
width <- ifelse(shiny::is.reactive(width), width(), width)
height <- ifelse(shiny::is.reactive(height), height(), height)
ppi <- ifelse(shiny::is.reactive(ppi), ppi(), ppi)
scale <- ifelse(shiny::is.reactive(scale), scale(), scale)

if(!is.numeric(width) || width <= 0) {
width <- "auto"
Expand All @@ -142,7 +144,8 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",

list(width = width,
height = height,
ppi = ppi)
ppi = ppi,
scale = scale)
})

# Fetch the reactive guide for this module
Expand Down Expand Up @@ -205,7 +208,10 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
}
})

#reset ui
# clear plot
clearPlot <- shiny::reactiveVal(FALSE)

# reset ui
shiny::observeEvent(input$reset, {
shinyjs::reset("cluster.distance")
shinyjs::reset("cluster.method")
Expand All @@ -220,6 +226,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
if(!is.null(custom.row.label)) {
custom_label <<- shiny::callModule(label, "labeller", data = custom.row.label, label = "Select row label", sep = label.sep, disable = shiny::reactive(!input$row.label))
}
clearPlot(TRUE)
})

columns <- shiny::callModule(columnSelector, "select", type.columns = types, columnTypeLabel = "Column types to choose from")
Expand Down Expand Up @@ -249,6 +256,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
plot <- shiny::eventReactive(input$plot, {
# enable downloadButton
shinyjs::enable("download")
clearPlot(FALSE)

#new progress indicator
progress <- shiny::Progress$new()
Expand Down Expand Up @@ -277,6 +285,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
width = size()$width,
height = size()$height,
ppi = size()$ppi,
scale = size()$scale,
plot.method = plot.method,
winsorize.colors = colorPicker()$winsorize
)
Expand All @@ -292,16 +301,20 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
})

output$interactive <- plotly::renderPlotly({
#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Render plot")
if(clearPlot()) {
return()
} else {
#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Render plot")

plot <- plot()$plot
plot <- plot()$plot

progress$set(1)
progress$set(1)

return(plot)
return(plot)
}
})
}else{
output$heatmap <- shiny::renderUI({
Expand All @@ -312,15 +325,19 @@ heatmap <- function(input, output, session, data, types, plot.method = "static",
width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)),
height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)),
{
#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Render plot")
if(clearPlot()) {
return()
} else {
#new progress indicator
progress <- shiny::Progress$new()
on.exit(progress$close())
progress$set(0.2, message = "Render plot")

plot <- plot()$plot
plot <- plot()$plot

progress$set(1)
return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom"))
progress$set(1)
return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom"))
}
})
}

Expand Down
5 changes: 5 additions & 0 deletions R/limit.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ limitUI <- function(id, label = "Limit"){
#'
#' @export
limit <- function(input, output, session, lower = NULL, upper = NULL){
# reset on re-run
shinyjs::reset("enable")
shinyjs::reset("lowerLimit")
shinyjs::reset("upperLimit")

# evaluate reactive parameter
lower.r <- shiny::reactive({
if(shiny::is.reactive(lower)) {
Expand Down
Loading