Skip empty QC plots

This commit is contained in:
2024-09-01 17:04:49 -04:00
parent 6b1428a384
commit c6c4870d46

View File

@@ -194,6 +194,13 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
generate_and_save_plots <- function(df, output_dir, prefix, variables, include_qc = FALSE) {
plots <- list()
if (nrow(df) == 0) {
message("The \"", deparse(substitute(df)), "\" dataframe is empty, skipping plots")
return()
}
message("Generating plots for \"", deparse(substitute(df)), "\" dataframe")
for (var in variables) {
scatter_plot <-
generate_plot(df, x_var = "scan", y_var = var, plot_type = "scatter",
@@ -269,7 +276,7 @@ save_plots <- function(file_name, plot_list, output_dir) {
# Save to HTML with horizontal legend orientation
lapply(names(plot_list), function(plot_name) {
message("Processing plot: ", plot_name)
message("Generating plot: ", plot_name)
pgg <- tryCatch({
suppressWarnings(ggplotly(plot_list[[plot_name]]) %>%
layout(legend = list(orientation = "h")))