diff --git a/R/function.R b/R/function.R index c193ab6..541f3b1 100644 --- a/R/function.R +++ b/R/function.R @@ -23,13 +23,14 @@ #' @param height Set plot height in cm (Default = "auto"). #' @param ppi Pixel per inch (default = 72). #' @param plot.method Whether the plot should be 'interactive' or 'static' (Default = 'static'). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @import data.table #' #' @return Returns list(plot = ggplotly/ ggplot, width, height, ppi, exceed_size). -create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize = 3, colors = NULL, x_label = "", y_label = "", z_label = "", density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", ppi = 72, plot.method = "static"){ +create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize = 3, colors = NULL, x_label = "", y_label = "", z_label = "", density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", ppi = 72, plot.method = "static", scale = 1){ ########## prepare data ########## #set labelnames if needed x_label <- ifelse(nchar(x_label), x_label, names(data)[2]) @@ -50,10 +51,10 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize if(ncol(data) >= 4){ z_head <- names(data)[4]} #delete rows where both 0 or at least one NA - rows.to.keep.data <- which(as.logical((data[,2] != 0) + (data[,3] != 0))) + rows.to.keep.data <- which(as.logical((data[, 2] != 0) + (data[, 3] != 0))) data <- data[rows.to.keep.data] if(!is.null(highlight.data)){ - rows.to.keep.high <- which(as.logical((highlight.data[,2] != 0) + (highlight.data[,3 != 0]))) + rows.to.keep.high <- which(as.logical((highlight.data[, 2] != 0) + (highlight.data[, 3 != 0]))) highlight.data <- highlight.data[rows.to.keep.high] } @@ -71,11 +72,12 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize panel.grid.minor = ggplot2::element_blank(), panel.border = ggplot2::element_blank(), panel.background = ggplot2::element_blank(), - axis.line.x = ggplot2::element_line(size=.3), - axis.line.y = ggplot2::element_line(size=.3), - axis.title.x = ggplot2::element_text(face="bold", color="black", size=10), - axis.title.y = ggplot2::element_text(face="bold", color="black", size=10), - plot.title = ggplot2::element_text(face="bold", color="black", size=12) + axis.line.x = ggplot2::element_line(size = .3), + axis.line.y = ggplot2::element_line(size = .3), + axis.title.x = ggplot2::element_text(face = "bold", color = "black", size = 10 * scale), + axis.title.y = ggplot2::element_text(face = "bold", color = "black", size = 10 * scale), + plot.title = ggplot2::element_text(face = "bold", color = "black", size = 12 * scale), + text = ggplot2::element_text(size = 10 * scale) # legend.background = element_rect(color = "red") #border color # legend.key = element_rect("green") #not working! ) @@ -148,7 +150,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize } #set points - plot <- plot + ggplot2::geom_point(size=pointsize, alpha=transparency, ggplot2::aes(text = hovertext)) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, ggplot2::aes(text = hovertext)) if(!is.null(highlight.data)){ #set highlighted hovertext @@ -164,27 +166,27 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize } #set highlighted points - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE, ggplot2::aes(text = hovertext.high)) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE, ggplot2::aes(text = hovertext.high)) } # static points without hovertexts } else if(plot.method == "static") { seed <- Sys.getpid() + Sys.time() # set points - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency) # set highlighted points if(!is.null(highlight.data)) { - plot <- plot + ggplot2::geom_point(size = pointsize, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE) + plot <- plot + ggplot2::geom_point(size = pointsize * scale, alpha = transparency, inherit.aes = TRUE, data = highlight.data, color = highlight.color, show.legend = FALSE) # set repelling point labels if(!is.null(highlight.labels)) { - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) } # set repelling labels (for only highlighted points shown) } else if(!is.null(highlight.labels) & length(highlight.labels) == nrow(data)) { - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) - plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, alpha = 0.5, seed = seed) + plot <- plot + ggrepel::geom_label_repel(data = highlight.data, mapping = ggplot2::aes(label = highlight.labels), size = labelsize * scale, color = "black", segment.color = "gray65", force = 2, max.iter = 1000, point.padding = grid::unit(0.1, "lines"), label.size = NA, fill = NA, seed = seed) } } @@ -234,6 +236,10 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize height <- height * (ppi / 2.54) } + # apply scale factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE limit <- 500 * (ppi / 2.54) @@ -252,9 +258,9 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize # add labels with arrows if(!is.null(highlight.labels)) { if(!is.null(highlight.data)) { - plot <- plotly::add_annotations(p = plot, x = highlight.data[[x_head]], y = highlight.data[[y_head]], text = highlight.labels, standoff = pointsize, font = list(size = labelsize), bgcolor = 'rgba(255, 255, 255, 0.5)') + plot <- plotly::add_annotations(p = plot, x = highlight.data[[x_head]], y = highlight.data[[y_head]], text = highlight.labels, standoff = pointsize * scale, font = list(size = labelsize * scale), bgcolor = 'rgba(255, 255, 255, 0.5)') } else if(nrow(data) == length(highlight.labels)) { - plot <- plotly::add_annotations(p = plot, x = data[[x_head]], y = data[[y_head]], text = highlight.labels, standoff = pointsize, font = list(size = labelsize), bgcolor = 'rgba(255, 255, 255, 0.5)') + plot <- plotly::add_annotations(p = plot, x = data[[x_head]], y = data[[y_head]], text = highlight.labels, standoff = pointsize * scale, font = list(size = labelsize * scale), bgcolor = 'rgba(255, 255, 255, 0.5)') } } } @@ -281,6 +287,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize #' @param width Set the width of the plot in cm (default = 28). #' @param height Set the height of the plot in cm (default = 28). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details If width and height are the same axis ratio will be set to one (quadratic plot). #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. @@ -288,7 +295,7 @@ create_scatterplot <- function(data, transparency = 1, pointsize = 1, labelsize #' @import data.table #' #' @return A named list(plot = ggplot object, data = pca.data, width = width of plot (cm), height = height of plot (cm), ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max). -create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72) { +create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72, scale = 1) { requireNamespace("FactoMineR", quietly = TRUE) requireNamespace("factoextra", quietly = TRUE) @@ -345,16 +352,16 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. panel.background = ggplot2::element_blank(), axis.line.x = ggplot2::element_line(size=.3), axis.line.y = ggplot2::element_line(size=.3), - axis.title.x = ggplot2::element_text(color="black", size=11), - axis.title.y = ggplot2::element_text(color="black", size=11), + axis.title.x = ggplot2::element_text(color="black", size = 11 * scale), + axis.title.y = ggplot2::element_text(color="black", size = 11 * scale), #plot.title = element_text(color="black", size=12), plot.title = ggplot2::element_blank(), - legend.title= ggplot2::element_blank(), - text= ggplot2::element_text(size = 12) #size for all (legend?) labels + legend.title = ggplot2::element_blank(), + text = ggplot2::element_text(size = 12 * scale) #size for all (legend?) labels #legend.key = element_rect(fill="white") ) - pca_plot <- factoextra::fviz_pca_ind(pca, axes = c(dimensionA, dimensionB), invisible = "none", pointsize = pointsize, label = "none", axes.linetype = "blank", repel = FALSE) + pca_plot <- factoextra::fviz_pca_ind(pca, axes = c(dimensionA, dimensionB), invisible = "none", pointsize = pointsize * scale, label = "none", axes.linetype = "blank", repel = FALSE) pca_plot <- pca_plot + theme1 if(labels) { @@ -362,7 +369,7 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. data = data.frame(pca$ind$coord), mapping = ggplot2::aes_(x = pca$ind$coord[, dimensionA], y = pca$ind$coord[, dimensionB], label = rownames(pca$ind$coord)), segment.color = "gray65", - size = labelsize, + size = labelsize * scale, force = 2, max.iter = 10000, point.padding = grid::unit(0.1, "lines") @@ -374,6 +381,10 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. # pca_plot <- pca_plot + ggplot2::coord_fixed(ratio = 1) # } + # add scale factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE if(width > 500) { @@ -405,11 +416,12 @@ create_pca <- function(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on. #' @param width Set width of plot in cm (Default = "auto"). #' @param height Set height of plot in cm (Default = "auto"). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @return Returns list(plot = complexHeatmap/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max) depending on plot.method. -create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label = NULL, column.label=T, column.custom.label = NULL, clustering='none', clustdist='auto', clustmethod='auto', colors=NULL, winsorize.colors = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72) { +create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label = NULL, column.label=T, column.custom.label = NULL, clustering='none', clustdist='auto', clustmethod='auto', colors=NULL, winsorize.colors = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) { requireNamespace("heatmaply", quietly = TRUE) requireNamespace("ComplexHeatmap", quietly = TRUE) requireNamespace("grDevices", quietly = TRUE) @@ -441,7 +453,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label if(plot.method == "interactive"){ #estimate label sizes #row label - rowlabel_size <- ifelse(row.label, max(nchar(data[[1]]), na.rm = TRUE) * 8, 0) + rowlabel_size <- ifelse(row.label, max(nchar(data[[1]]), na.rm = TRUE) * 8 * scale, 0) #column label collabel_size <- ifelse(column.label, (2 + log2(max(nchar(names(data)), na.rm = TRUE))^2) * 10, 0) #legend @@ -466,10 +478,14 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label #layout plot <- heatmaply::heatmaply(plot, plot_method = "ggplot", - scale_fill_gradient_fun = ggplot2::scale_fill_gradientn(colors = colors, name = unitlabel, limits = winsorize.colors, oob = scales::squish) + scale_fill_gradient_fun = ggplot2::scale_fill_gradientn(colors = colors, name = unitlabel, limits = winsorize.colors, oob = scales::squish), + heatmap_layers = ggplot2::theme(text = ggplot2::element_text(size = 12 * scale)) ) - plot <- plotly::layout(plot, autosize = ifelse(width == "auto", TRUE, FALSE), margin = list(l = rowlabel_size, r = legend, b = collabel_size)) + # scale axis ticks + ticks <- list(tickfont = list(size = 12 * scale)) + + plot <- plotly::layout(plot, autosize = ifelse(width == "auto", TRUE, FALSE), margin = list(l = rowlabel_size, r = legend, b = collabel_size), xaxis = ticks, yaxis2 = ticks) # decide which sizes should be used if(width == "auto") { @@ -481,6 +497,10 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label height <- auto_height } + # add scale + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE limit <- 500 * (ppi / 2.54) @@ -566,24 +586,29 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label show_column_names = column.label, row_names_side = "left", row_dend_side = "right", - row_dend_width = grid::unit(1, "inches"), - column_dend_height = grid::unit(1, "inches"), - row_names_max_width = grid::unit(8, "inches"), - column_names_max_height = grid::unit(4, "inches"), - row_names_gp = grid::gpar(fontsize = 12), - column_names_gp = grid::gpar(fontsize = 12), - column_title_gp = grid::gpar(fontsize = 10, units = "in"), + row_dend_width = grid::unit(1 * scale, "inches"), + # row_dend_gp = grid::gpar(lwd = 1, lex = scale), # don't seem to work + column_dend_height = grid::unit(1 * scale, "inches"), + # column_dend_gp = grid::gpar(lwd = 1, lex = scale), # don't seem to work + row_names_max_width = grid::unit(8 * scale, "inches"), + column_names_max_height = grid::unit(4 * scale, "inches"), + row_names_gp = grid::gpar(fontsize = 12 * scale), + column_names_gp = grid::gpar(fontsize = 12 * scale), + column_title_gp = grid::gpar(fontsize = 10 * scale, units = "in"), heatmap_legend_param = list( color_bar = "continuous", - legend_direction = "horizontal" + legend_direction = "horizontal", + title_gp = grid::gpar(fontsize = 10 * scale), + labels_gp = grid::gpar(fontsize = 8 * scale), + grid_height = grid::unit(0.15 * scale, "inches") ) ) #width/ height calculation - col_names_maxlength_label_width=max(sapply(colnames(prep.data), graphics::strwidth, units="in", font=12)) #longest column label when plotted in inches - col_names_maxlength_label_height=max(sapply(colnames(prep.data), graphics::strheight, units="in", font=12)) #highest column label when plotted in inches - row_names_maxlength_label_width=max(sapply(rownames(prep.data), graphics::strwidth, units="in", font=12)) #longest row label when plotted in inches - row_names_maxlength_label_height=max(sapply(rownames(prep.data), graphics::strheight, units="in", font=12)) #highest row label when plotted in inches + col_names_maxlength_label_width=max(sapply(colnames(prep.data), graphics::strwidth, units="in", font = 12)) #longest column label when plotted in inches + col_names_maxlength_label_height=max(sapply(colnames(prep.data), graphics::strheight, units="in", font = 12)) #highest column label when plotted in inches + row_names_maxlength_label_width=max(sapply(rownames(prep.data), graphics::strwidth, units="in", font = 12)) #longest row label when plotted in inches + row_names_maxlength_label_height=max(sapply(rownames(prep.data), graphics::strheight, units="in", font = 12)) #highest row label when plotted in inches # width if(row.label){ @@ -631,7 +656,7 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label height <- 500 } - plot <- list(plot = plot, width = width, height = height, ppi = ppi, exceed_size = exceed_size) + plot <- list(plot = plot, width = width * scale, height = height * scale, ppi = ppi, exceed_size = exceed_size) } return(plot) @@ -654,13 +679,14 @@ create_heatmap <- function(data, unitlabel='auto', row.label=T, row.custom.label #' @param width Set the width of the plot in cm (default = "auto"). #' @param height Set the height of the plot in cm (default = "auto"). #' @param ppi Pixel per inch (default = 72). +#' @param scale Modify plot size while preserving aspect ratio (Default = 1). #' #' @details Width/ height limit = 500. If exceeded default to 500 and issue exceed_size = TRUE. #' #' @import data.table #' #' @return Returns depending on plot.method list(plot = ggplot/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean). -create_geneview <- function(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72){ +create_geneview <- function(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1){ #grouping #group by factor if existing (fill with key if empty) grouping[grouping[[2]] == "", 2 := grouping[grouping[[2]] == "", 1]] @@ -763,7 +789,7 @@ create_geneview <- function(data, grouping, plot.type = "line", facet.target = " legend.position = "none", #remove legend legend.title = ggplot2::element_blank(), axis.title.x = ggplot2::element_blank(), - text = ggplot2::element_text(family = "mono", size = 15) + text = ggplot2::element_text(family = "mono", size = 15 * scale) #axis.line.x = element_line(size = .3), #axis.line.y = element_line(size = .3), @@ -957,6 +983,10 @@ create_geneview <- function(data, grouping, plot.type = "line", facet.target = " height <- auto_height } + # add scaleing factor + width <- width * scale + height <- height * scale + # size exceeded? exceed_size <- FALSE if(width > 500) { diff --git a/R/geneView.R b/R/geneView.R index 5d39c9f..3aba4f4 100644 --- a/R/geneView.R +++ b/R/geneView.R @@ -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. @@ -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)){ @@ -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" @@ -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 @@ -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, { log_message("GeneView: reset", "INFO", token = session$token) @@ -172,6 +179,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({ @@ -259,6 +267,7 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -286,7 +295,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 ) log_message("GeneView: done.", "INFO", token = session$token) @@ -332,33 +342,42 @@ geneView <- function(input, output, session, data, metadata, level = NULL, plot. if(plot.method == "interactive") { output$interactive <- plotly::renderPlotly({ - log_message("GeneView: render plot interactive", "INFO", token = session$token) + if(clearPlot()) { + return() + } else { + log_message("GeneView: render plot interactive", "INFO", token = session$token) - #progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(message = "Rendering plot", value = 0) + #progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(message = "Rendering plot", value = 0) - plot <- plot()$plot + plot <- plot()$plot - progress$set(value = 1) - return(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)), { - log_message("GeneView: render plot static", "INFO", token = session$token) - #progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(message = "Rendering plot", value = 0.3) + if(clearPlot()) { + return() + } else { + log_message("GeneView: render plot static", "INFO", token = session$token) - plot <- plot()$plot + #progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(message = "Rendering plot", value = 0.3) - progress$set(value = 1) - return(plot) + plot <- plot()$plot + + progress$set(value = 1) + return(plot) + } }) } diff --git a/R/global_cor_heatmap.R b/R/global_cor_heatmap.R index c6c10ac..e196d60 100644 --- a/R/global_cor_heatmap.R +++ b/R/global_cor_heatmap.R @@ -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({ @@ -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" @@ -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 @@ -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, { log_message("Global correlation heatmap: reset", "INFO", token = session$token) @@ -232,6 +238,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 @@ -312,6 +319,8 @@ global_cor_heatmap <- function(input, output, session, data, types, plot.method # enable downloadButton shinyjs::enable("download") + # show plot + clearPlot(FALSE) # progress indicator progress <- shiny::Progress$new() @@ -350,7 +359,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 @@ -366,38 +376,46 @@ 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)), { - log_message("Global correlation heatmap: render plot static", "INFO", token = session$token) + if(clearPlot()) { + return() + } else { + log_message("Global correlation heatmap: render plot static", "INFO", token = session$token) - # progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Rendering plot") + # progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Rendering plot") - # get plot - plot <- plot()$plot + # get plot + plot <- plot()$plot - # update progress indicator - progress$set(1) + # update progress indicator + progress$set(1) - # draw plot - return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + # draw plot + return(ComplexHeatmap::draw(plot, heatmap_legend_side = "bottom")) + } } ) }else if(plot.method == "interactive") { output$interactive <- plotly::renderPlotly({ - log_message("Global correlation heatmap: render plot interactive", "INFO", token = session$token) + if(clearPlot()) { + return() + } else { + log_message("Global correlation heatmap: render plot interactive", "INFO", token = session$token) - # progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Rendering plot") + # progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Rendering plot") - plot <- plot()$plot + plot <- plot()$plot - # update progress indicator - progress$set(1) + # update progress indicator + progress$set(1) - return(plot) + return(plot) + } }) } diff --git a/R/heatmap.R b/R/heatmap.R index b1454d2..74aab83 100644 --- a/R/heatmap.R +++ b/R/heatmap.R @@ -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 @@ -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" @@ -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 @@ -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, { log_message("Heatmap: reset", "INFO", token = session$token) @@ -222,6 +228,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") @@ -253,6 +260,7 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -281,6 +289,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 ) @@ -297,18 +306,22 @@ heatmap <- function(input, output, session, data, types, plot.method = "static", }) output$interactive <- plotly::renderPlotly({ - log_message("Heatmap: render plot interactive", "INFO", token = session$token) + if(clearPlot()) { + return() + } else { + log_message("Heatmap: render plot interactive", "INFO", token = session$token) - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") + #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({ @@ -319,17 +332,21 @@ 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)), { - log_message("Heatmap: render plot static", "INFO", token = session$token) + if(clearPlot()) { + return() + } else { + log_message("Heatmap: render plot static", "INFO", token = session$token) - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") + #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")) + } }) } diff --git a/R/limit.R b/R/limit.R index 9b3e436..e7499f7 100644 --- a/R/limit.R +++ b/R/limit.R @@ -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)) { diff --git a/R/pca.R b/R/pca.R index 8a4ba43..642fb7f 100644 --- a/R/pca.R +++ b/R/pca.R @@ -77,6 +77,7 @@ pcaUI <- function(id, show.label = TRUE) { #' @param width Width of the plot in cm. Defaults to 28 and supports reactive. #' @param height Height of the plot in cm. Defaults to 28 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 zero will use default value. #' @@ -85,7 +86,7 @@ pcaUI <- function(id, show.label = TRUE) { #' @import data.table #' #' @export -pca <- function(input, output, session, data, types, levels = NULL, entryLabel = NULL, width = 28, height = 28, ppi = 72) { +pca <- function(input, output, session, data, types, levels = NULL, entryLabel = NULL, width = 28, height = 28, ppi = 72, scale = 1) { #handle reactive data data.r <- shiny::reactive({ if(shiny::is.reactive(data)){ @@ -124,6 +125,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = 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 <- 28 @@ -137,7 +139,8 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) @@ -146,6 +149,9 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = rintrojs::introjs(session, options = list(steps = guide())) }) + # clear plot + clearPlot <- shiny::reactiveVal(value = FALSE) + #reset ui shiny::observeEvent(input$reset, { log_message("PCA: reset", "INFO", token = session$token) @@ -156,6 +162,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = shinyjs::reset("pointsize") shinyjs::reset("labelsize") columnSelect <<- shiny::callModule(columnSelector, "select", type.columns = shiny::reactive(types.r()[level %in% levels.r(), c("key", "level"), with = FALSE]), columnTypeLabel = "Column types to choose from") + clearPlot(TRUE) }) columnSelect <- shiny::callModule(columnSelector, "select", type.columns = shiny::reactive(types.r()[level %in% levels.r(), c("key", "level"), with = FALSE]), columnTypeLabel = "Column types to choose from") @@ -234,6 +241,7 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = # enable downloadButton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -252,13 +260,17 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = on.columns = TRUE, width = size()$width, height = size()$height, - ppi = size()$ppi + ppi = size()$ppi, + scale = size()$scale ) progress$set(1) log_message("PCA: done.", "INFO", token = session$token) + # show plot + shinyjs::show("pca") + return(plot) }) @@ -278,8 +290,13 @@ pca <- function(input, output, session, data, types, levels = NULL, entryLabel = width = plot_width, height = plot_height, { - log_message("PCA: render plot", "INFO", token = session$token) - computed.data()$plot + if(clearPlot()){ + return() + } else { + log_message("PCA: render plot", "INFO", token = session$token) + + computed.data()$plot + } }) #group data by dimension diff --git a/R/scatterPlot.R b/R/scatterPlot.R index e08afcc..d72befa 100644 --- a/R/scatterPlot.R +++ b/R/scatterPlot.R @@ -123,13 +123,14 @@ scatterPlotUI <- 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 Returns reactive containing data used for plot. #' #' @details Make sure to have the same columnnames in data and features. #' #' @export -scatterPlot <- function(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72) { +scatterPlot <- function(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", height = "auto", ppi = 72, scale = 1) { #handle reactive data data.r <- shiny::reactive({ if(shiny::is.reactive(data)){ @@ -155,6 +156,7 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma 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" @@ -168,7 +170,8 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma list(width = width, height = height, - ppi = ppi) + ppi = ppi, + scale = scale) }) #Fetch the reactive guide for this module @@ -180,6 +183,9 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma data_x <- shiny::reactive(as.matrix(data.r()[, xaxis$selectedColumn(), with = FALSE])) data_y <- shiny::reactive(as.matrix(data.r()[, yaxis$selectedColumn(), with = FALSE])) + # clear plot + clearPlot <- shiny::reactiveVal(FALSE) + #reset ui shiny::observeEvent(input$reset, { log_message("Scatterplot: reset", "INFO", token = session$token) @@ -194,8 +200,9 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma colorPicker <<- shiny::callModule(colorPicker2, "color", distribution = list("sequential", "diverging"), winsorize = winsorize) transform_x <<- shiny::callModule(transformation, "transform_x", data = data_x) transform_y <<- shiny::callModule(transformation, "transform_y", data = data_y) - limit_x <<- shiny::callModule(limit, "xaxis_limit", lower = shiny::reactive(get_x_limit()[1]), upper = shiny::reactive(get_x_limit()[2])) - limit_y <<- shiny::callModule(limit, "yaxis_limit", lower = shiny::reactive(get_y_limit()[1]), upper = shiny::reactive(get_y_limit()[2])) + limit_x <<- shiny::callModule(limit, "xaxis_limit", lower = shiny::reactive(result.data()$xlim[1]), upper = shiny::reactive(result.data()$xlim[2])) + limit_y <<- shiny::callModule(limit, "yaxis_limit", lower = shiny::reactive(result.data()$ylim[1]), upper = shiny::reactive(result.data()$ylim[2])) + clearPlot(TRUE) }) winsorize <- shiny::reactive({ @@ -310,6 +317,7 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma #enable downloadbutton shinyjs::enable("download") + clearPlot(FALSE) #new progress indicator progress <- shiny::Progress$new() @@ -349,7 +357,8 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma plot.method = plot.method, width = size()$width, height = size()$height, - ppi = size()$ppi + ppi = size()$ppi, + scale = size()$scale ) progress$set(1) @@ -375,24 +384,33 @@ scatterPlot <- function(input, output, session, data, types, features = NULL, ma width = shiny::reactive(plot()$width * (plot()$ppi / 2.54)), height = shiny::reactive(plot()$height * (plot()$ppi / 2.54)), { - log_message("Scatterplot: render plot static", "INFO", token = session$token) - plot()$plot + if(clearPlot()) { + return() + } else { + log_message("Scatterplot: render plot static", "INFO", token = session$token) + + plot()$plot + } } ) } else if(plot.method == "interactive") { output$interactive <- plotly::renderPlotly({ - log_message("Scatterplot: render plot interactive", "INFO", token = session$token) - #new progress indicator - progress <- shiny::Progress$new() - on.exit(progress$close()) - progress$set(0.2, message = "Render plot") + if(clearPlot()) { + return() + } else { + log_message("Scatterplot: render plot interactive", "INFO", token = session$token) - plot <- plot()$plot + #new progress indicator + progress <- shiny::Progress$new() + on.exit(progress$close()) + progress$set(0.2, message = "Render plot") - progress$set(1) - return(plot) - }) + plot <- plot()$plot + progress$set(1) + return(plot) + } + }) } output$download <- shiny::downloadHandler(filename = "scatterPlot.zip", diff --git a/exec/geneView_example.R b/exec/geneView_example.R index bddb915..4441db5 100644 --- a/exec/geneView_example.R +++ b/exec/geneView_example.R @@ -18,7 +18,8 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody(fluidPage( geneViewUI("id") ))) @@ -34,7 +35,7 @@ server <- function(input, output) { metadata[level != "annotation"][["level"]] }) - gene <- callModule(geneView, "id", data = table.r, metadata.r, level.r, custom.label = table.r, plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + gene <- callModule(geneView, "id", data = table.r, metadata.r, level.r, custom.label = table.r, plot.method = "static", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(gene()) diff --git a/exec/global_cor_heatmap_example.R b/exec/global_cor_heatmap_example.R index 361273b..01d31f5 100644 --- a/exec/global_cor_heatmap_example.R +++ b/exec/global_cor_heatmap_example.R @@ -17,7 +17,8 @@ ui <- dashboardPage( header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody( fluidPage( @@ -27,7 +28,7 @@ ui <- dashboardPage( ) server <- function(input, output) { - table <- shiny::callModule(global_cor_heatmap, "id", data = data, types = metadata[type %in% c("performance", "design")], plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + table <- shiny::callModule(global_cor_heatmap, "id", data = data, types = metadata[type %in% c("performance", "design")], plot.method = "static", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) shiny::observe({ print(table()) diff --git a/exec/heatmap_example.R b/exec/heatmap_example.R index 53e083b..771c75e 100644 --- a/exec/heatmap_example.R +++ b/exec/heatmap_example.R @@ -18,7 +18,8 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", value = 1, min = 1, max = 10) ), dashboardBody(fluidPage( heatmapUI("id") ))) @@ -32,7 +33,7 @@ server <- function(input, output) { metadata[ type != "annotation"] }) - heat <- callModule(heatmap, "id", data = table, types = typ, plot.method = "static", custom.row.label = table, width = reactive(input$width), height = reactive(input$height)) + heat <- callModule(heatmap, "id", data = table, types = typ, plot.method = "interactive", custom.row.label = table, width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(heat()) diff --git a/exec/pca_example.R b/exec/pca_example.R index 7cc78af..d7be244 100644 --- a/exec/pca_example.R +++ b/exec/pca_example.R @@ -14,13 +14,14 @@ names(metadata)[1] <- "key" ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", min = 1, max = 10, value = 1) ), dashboardBody(fluidPage( pcaUI("id") ))) server <- function(input, output) { - callModule(pca, "id", data = data, types = metadata, levels = metadata[level != "annotation"][["level"]], width = reactive(input$width), height = reactive(input$height)) + callModule(pca, "id", data = data, types = metadata, levels = metadata[level != "annotation"][["level"]], width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) } # Run the application diff --git a/exec/scatterPlot_example.R b/exec/scatterPlot_example.R index d65489c..2728010 100644 --- a/exec/scatterPlot_example.R +++ b/exec/scatterPlot_example.R @@ -20,7 +20,8 @@ ui <- dashboardPage(header = dashboardHeader(), sidebar = dashboardSidebar( markerUI("marker"), numericInput(inputId = "width", label = "width in cm", value = 0, min = 0), - numericInput(inputId = "height", label = "height in cm", value = 0, min = 0) + numericInput(inputId = "height", label = "height in cm", value = 0, min = 0), + sliderInput(inputId = "scale", label = "scale plot", min = 1, max = 10, value = 1) ), body = dashboardBody( fluidPage( @@ -32,7 +33,7 @@ ui <- dashboardPage(header = dashboardHeader(), server <- function(input, output) { marker <- callModule(marker, "marker", data) # highlight all manual cars - plot <- callModule(scatterPlot, "id", data = data, types = metadata[level != "annotation"], features = data[am == 1], markerReac = marker, plot.method = "static", width = reactive(input$width), height = reactive(input$height)) + plot <- callModule(scatterPlot, "id", data = data, types = metadata[level != "annotation"], features = data[am == 1], markerReac = marker, plot.method = "interactive", width = reactive(input$width), height = reactive(input$height), scale = reactive(input$scale)) observe({ print(plot()) diff --git a/man/create_geneview.Rd b/man/create_geneview.Rd index 7117b8a..8ca3d08 100644 --- a/man/create_geneview.Rd +++ b/man/create_geneview.Rd @@ -7,7 +7,7 @@ create_geneview(data, grouping, plot.type = "line", facet.target = "gene", facet.cols = 2, colors = NULL, ylabel = NULL, ylimits = NULL, gene.label = NULL, plot.method = "static", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{data}{data.table containing plot data} @@ -37,6 +37,8 @@ column2 : factor1} \item{height}{Set the height of the plot in cm (default = "auto").} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns depending on plot.method list(plot = ggplot/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean). diff --git a/man/create_heatmap.Rd b/man/create_heatmap.Rd index e626291..c425135 100644 --- a/man/create_heatmap.Rd +++ b/man/create_heatmap.Rd @@ -8,7 +8,7 @@ create_heatmap(data, unitlabel = "auto", row.label = T, row.custom.label = NULL, column.label = T, column.custom.label = NULL, clustering = "none", clustdist = "auto", clustmethod = "auto", colors = NULL, winsorize.colors = NULL, plot.method = "static", - width = "auto", height = "auto", ppi = 72) + width = "auto", height = "auto", ppi = 72, scale = 1) } \arguments{ \item{data}{data.table containing plot data. First column contains row labels.} @@ -40,6 +40,8 @@ create_heatmap(data, unitlabel = "auto", row.label = T, \item{height}{Set height of plot in cm (Default = "auto").} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns list(plot = complexHeatmap/ plotly object, width = width in cm, height = height in cm, ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max) depending on plot.method. diff --git a/man/create_pca.Rd b/man/create_pca.Rd index 044613d..fbb0e70 100644 --- a/man/create_pca.Rd +++ b/man/create_pca.Rd @@ -6,7 +6,8 @@ \usage{ create_pca(data, dimensionA = 1, dimensionB = 2, dimensions = 6, on.columns = TRUE, labels = FALSE, custom.labels = NULL, - pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72) + pointsize = 2, labelsize = 3, width = 28, height = 28, ppi = 72, + scale = 1) } \arguments{ \item{data}{data.table from which the plot is created (First column will be handled as rownames if not numeric).} @@ -32,6 +33,8 @@ create_pca(data, dimensionA = 1, dimensionB = 2, dimensions = 6, \item{height}{Set the height of the plot in cm (default = 28).} \item{ppi}{Pixel per inch (default = 72).} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ A named list(plot = ggplot object, data = pca.data, width = width of plot (cm), height = height of plot (cm), ppi = pixel per inch, exceed_size = Boolean whether width/ height exceeded max). diff --git a/man/create_scatterplot.Rd b/man/create_scatterplot.Rd index 8c3985d..1eb26de 100644 --- a/man/create_scatterplot.Rd +++ b/man/create_scatterplot.Rd @@ -9,7 +9,7 @@ create_scatterplot(data, transparency = 1, pointsize = 1, labelsize = 3, density = T, line = T, categorized = F, highlight.data = NULL, highlight.labels = NULL, highlight.color = "#FF0000", xlim = NULL, ylim = NULL, colorbar.limits = NULL, width = "auto", height = "auto", - ppi = 72, plot.method = "static") + ppi = 72, plot.method = "static", scale = 1) } \arguments{ \item{data}{data.table containing plot data @@ -55,6 +55,8 @@ column 2, 3(, 4): x, y(, z)} \item{ppi}{Pixel per inch (default = 72).} \item{plot.method}{Whether the plot should be 'interactive' or 'static' (Default = 'static').} + +\item{scale}{Modify plot size while preserving aspect ratio (Default = 1).} } \value{ Returns list(plot = ggplotly/ ggplot, width, height, ppi, exceed_size). diff --git a/man/geneView.Rd b/man/geneView.Rd index b33b235..b8e755d 100644 --- a/man/geneView.Rd +++ b/man/geneView.Rd @@ -6,7 +6,7 @@ \usage{ geneView(input, output, session, data, metadata, level = NULL, plot.method = "static", custom.label = NULL, label.sep = ", ", - width = "auto", height = "auto", ppi = 72) + width = "auto", height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object.} @@ -38,6 +38,8 @@ column3: level (condition type)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data.table used for plotting. diff --git a/man/global_cor_heatmap.Rd b/man/global_cor_heatmap.Rd index 8f3a512..80e86b8 100644 --- a/man/global_cor_heatmap.Rd +++ b/man/global_cor_heatmap.Rd @@ -5,7 +5,8 @@ \title{global correlation heatmap module server logic} \usage{ global_cor_heatmap(input, output, session, data, types, - plot.method = "static", width = "auto", height = "auto", ppi = 72) + plot.method = "static", width = "auto", height = "auto", ppi = 72, + scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -29,6 +30,8 @@ column4 = sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data used for plotting. diff --git a/man/heatmap.Rd b/man/heatmap.Rd index cd9bd68..077dbf4 100644 --- a/man/heatmap.Rd +++ b/man/heatmap.Rd @@ -6,7 +6,7 @@ \usage{ heatmap(input, output, session, data, types, plot.method = "static", custom.row.label = NULL, label.sep = ", ", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -34,6 +34,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Reactive containing data used for plotting. diff --git a/man/pca.Rd b/man/pca.Rd index c6f509e..eee0778 100644 --- a/man/pca.Rd +++ b/man/pca.Rd @@ -5,7 +5,7 @@ \title{pca module server logic} \usage{ pca(input, output, session, data, types, levels = NULL, entryLabel = NULL, - width = 28, height = 28, ppi = 72) + width = 28, height = 28, ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -31,6 +31,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to 28 and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ A reactive containing list with dimensions. diff --git a/man/scatterPlot.Rd b/man/scatterPlot.Rd index c7e94e6..53dc5c2 100644 --- a/man/scatterPlot.Rd +++ b/man/scatterPlot.Rd @@ -6,7 +6,7 @@ \usage{ scatterPlot(input, output, session, data, types, features = NULL, markerReac = NULL, plot.method = "static", width = "auto", - height = "auto", ppi = 72) + height = "auto", ppi = 72, scale = 1) } \arguments{ \item{input}{Shiny's input object} @@ -34,6 +34,8 @@ column4: sub_label (optional, added to id/ label)} \item{height}{Height of the plot in cm. Defaults to minimal size for readable labels and supports reactive.} \item{ppi}{Pixel per inch. Defaults to 72 and supports reactive.} + +\item{scale}{Scale plot size. Defaults to 1, supports reactive.} } \value{ Returns reactive containing data used for plot.