diff --git a/NEWS.md b/NEWS.md index 4d82ae3..caf372a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ * Used `dplyr::bind_rows()` instead of `rbind()` in the ShinyApp's `get_merged_db_list()` to allow merging of datasets with different rows (and probably from different databases) * Added `tryCatch()` to ShinyApp's `merge_input_files()` to raise an error in case the rbind fails (possibly because of divergences in column names/number) and warn the user that the files provided are not compatible for merging * Added 'quote' tabpanels alongside all `fileInput()` calls to determine quotation of input datasets +* Added download buttons for plots in ShinyApp +* Added package logo to plots # biblioverlap 1.0.3 diff --git a/R/06-plots_and_app.R b/R/06-plots_and_app.R index 0b33cb2..f7a0056 100644 --- a/R/06-plots_and_app.R +++ b/R/06-plots_and_app.R @@ -29,17 +29,23 @@ add_logo_to_plot <- function(plot, interpolate = TRUE, ... ) { + # Getting graphics device + previous_device <- grDevices::dev.cur() + + # Set up null graphics device to avoid unintentional plotting + grDevices::pdf(NULL) + # Set up the layout for the main plot and logo layout <- grid::grid.layout(nrow = 1, ncol = 1) -# + ## Create a new page with the specified layout grid::grid.newpage() grid::pushViewport(grid::viewport(layout = layout)) -# + ## Plot the Venn diagram on the left grid::pushViewport(grid::viewport(layout.pos.col = 1)) print(plot, newpage = FALSE) -# + ## Clear the viewport before adding the logo grid::popViewport(1) @@ -47,9 +53,9 @@ add_logo_to_plot <- function(plot, logo_raw <- png::readPNG(logo_path) #Importing logo into R logo <- matrix(grDevices::rgb(logo_raw[,,1],logo_raw[,,2],logo_raw[,,3], logo_raw[,,4] * alpha), nrow=dim(logo_raw)[1]) #Adding transparency to logo - source: https://stackoverflow.com/questions/11357926/r-add-alpha-value-to-png-image - # Ploting logo on the right + # Pushing viewport grid::pushViewport(grid::viewport(layout.pos.col = 1)) - + # Ploting logo grid::grid.raster(logo, width = width, height = height, @@ -65,10 +71,12 @@ add_logo_to_plot <- function(plot, #Generate combined plot combined_plot <- grid::grid.grab(wrap.grobs = TRUE ) - #Generate final plot + #Generate final plot (ggplot-like object) final_plot <- cowplot::ggdraw() + cowplot::draw_plot(combined_plot) + # Go back to previous graphics device + grDevices::dev.set(previous_device) #Return the final graphical object return( final_plot ) diff --git a/inst/biblioverApp/server.R b/inst/biblioverApp/server.R index ec2db1e..e6ac4ea 100644 --- a/inst/biblioverApp/server.R +++ b/inst/biblioverApp/server.R @@ -197,18 +197,20 @@ server <- function(input, output, session) { #### Generating plots (reactive functions) summary_plot <- reactive( { - biblioverlap::plot_matching_summary(calculate_results()$summary, + summary <- biblioverlap::plot_matching_summary(calculate_results()$summary, text_size = input$summary_text_size, size = input$summary_value_size) + return(summary) }) venn_plot <- reactive( { - biblioverlap::plot_venn(calculate_results()$db_list, + venn <- biblioverlap::plot_venn(calculate_results()$db_list, label = input$venn_label, label_color = input$venn_label_color, label_size = input$venn_label_size, label_alpha = input$venn_label_alpha, set_size = input$venn_set_size ) + return(venn) } ) # Upset plots from UpSetR can hide its empty intersections if a NULL value is passed to its `empty.intersections` parameter @@ -220,7 +222,7 @@ server <- function(input, output, session) { }) upset_plot <- reactive ({ - biblioverlap::plot_upset(calculate_results()$db_list, + upset <- biblioverlap::plot_upset(calculate_results()$db_list, nsets = length(db_list), nintersects = input$nintersects, order.by = input$order.by, @@ -231,6 +233,7 @@ server <- function(input, output, session) { show.numbers = input$show.numbers, mb.ratio = c(input$mb.ratio, 1 - input$mb.ratio) ) + return(upset) } ) #Displaying plots in shinyApp (renderPlot functions) @@ -264,6 +267,7 @@ server <- function(input, output, session) { content = function(file) { ggplot2::ggsave(file, plot = plot_obj, limitsize = FALSE, + bg = 'white', height = input$plot_height, width = input$plot_width, units = 'px', dpi = 'screen'