From f0a8bce297a0cd3f8dc010694117c16069abd546 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Tue, 30 Aug 2022 10:13:28 +0200 Subject: [PATCH] gsea: Properly show empty results --- R/gsea.R | 130 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 45 deletions(-) diff --git a/R/gsea.R b/R/gsea.R index 4003426..c69d291 100644 --- a/R/gsea.R +++ b/R/gsea.R @@ -17,13 +17,33 @@ gsea_ui <- function(id) { style = "margin-left: 16px" ) ), - div( - style = "margin-top: 16px", - plotly::plotlyOutput(NS(id, "plot")), - ), - div( - style = "margin-top: 16px", - DT::DTOutput(NS(id, "details")) + tabsetPanel( + id = NS(id, "results"), + type = "hidden", + tabPanelBody( + "some", + div( + style = "margin-top: 16px", + plotly::plotlyOutput(NS(id, "plot")), + ), + div( + style = "margin-top: 16px", + DT::DTOutput(NS(id, "details")) + ) + ), + tabPanelBody( + "none", + div( + style = "margin-top: 32px", + h5("No results"), + div( + "The enrichment analysis using g:Profiler yielded no results. ", + "You can change the parameters of the ranking and the filter ", + "criteria. Click the \"Update analysis\" button to rerun the ", + "analysis." + ) + ) + ) ) ) } @@ -55,51 +75,71 @@ gsea_server <- function(id, ranking) { bindCache(ranking_filtered()) |> bindEvent(input$gsea_run, ignoreNULL = FALSE) - output$plot <- plotly::renderPlotly({ - gprofiler2::gostplot( - gsea_analysis(), - capped = FALSE, - interactive = TRUE + observe({ + updateTabsetPanel( + session, + "results", + selected = if (!is.null(gsea_analysis()$result)) { + "some" + } else { + "none" + } ) }) + output$plot <- plotly::renderPlotly({ + if (!is.null(gsea_analysis()$result)) { + gprofiler2::gostplot( + gsea_analysis(), + capped = FALSE, + interactive = TRUE + ) + } else { + plotly::plotly_empty() + } + }) + output$details <- DT::renderDT({ - data <- data.table(gsea_analysis()$result) - setorder(data, p_value) + if (!is.null(gsea_analysis()$result)) { + data <- data.table(gsea_analysis()$result) + setorder(data, p_value) - data[, total_ratio := term_size / effective_domain_size] - data[, query_ratio := intersection_size / query_size] - data[, increase := (query_ratio - total_ratio) / total_ratio] + data[, total_ratio := term_size / effective_domain_size] + data[, query_ratio := intersection_size / query_size] + data[, increase := (query_ratio - total_ratio) / total_ratio] - data <- data[, .( - source, - term_name, - total_ratio, - query_ratio, - increase, - p_value - )] + data <- data[, .( + source, + term_name, + total_ratio, + query_ratio, + increase, + p_value + )] - DT::datatable( - data, - rownames = FALSE, - colnames = c( - "Source", - "Term", - "Total ratio", - "Query ratio", - "Increase", - "p-value" - ), - options = list( - pageLength = 25 - ) - ) |> - DT::formatRound("p_value", digits = 4) |> - DT::formatPercentage( - c("total_ratio", "query_ratio", "increase"), - digits = 2 - ) + DT::datatable( + data, + rownames = FALSE, + colnames = c( + "Source", + "Term", + "Total ratio", + "Query ratio", + "Increase", + "p-value" + ), + options = list( + pageLength = 25 + ) + ) |> + DT::formatRound("p_value", digits = 4) |> + DT::formatPercentage( + c("total_ratio", "query_ratio", "increase"), + digits = 2 + ) + } else { + DT::datatable(data.table()) + } }) }) }