diff --git a/R/server.R b/R/server.R index 61f9b98..e5b152d 100644 --- a/R/server.R +++ b/R/server.R @@ -22,7 +22,18 @@ server <- function(input, output) { }) output$scores_plot <- plotly::renderPlotly(scores_plot(ranked_data())) - output$ranked_data <- DT::renderDataTable(genes_table(ranked_data())) + + output$selected_genes <- DT::renderDataTable({ + selected_points <- plotly::event_data("plotly_selected") + + data <- if (is.null(selected_points)) { + ranked_data() + } else { + ranked_data()[rank %in% selected_points$x] + } + + genes_table(data) + }) } #' Create plot showing the distribution of scores using `plotly`. @@ -63,7 +74,9 @@ scores_plot <- function(ranked_data, ranks = 1000) { ) |> plotly::layout( xaxis = list(title = ranks_label), - yaxis = list(title = "Score") + yaxis = list(title = "Score"), + clickmode = "event+select", + dragmode = "select" ) } diff --git a/R/ui.R b/R/ui.R index bb3654f..ab29e5c 100644 --- a/R/ui.R +++ b/R/ui.R @@ -41,17 +41,15 @@ ui <- function() { ), mainPanel( width = 9, - tabsetPanel( - type = "pills", - tabPanel( - title = "Distribution of scores", - plotly::plotlyOutput("scores_plot") - ), - tabPanel( - title = "Detailed results", - DT::dataTableOutput("ranked_data") - ) - ) + h3("Distribution of scores"), + div(paste0( + "Note: Click or drag within the figure to select ", + "genes of interest." + )), + plotly::plotlyOutput("scores_plot"), + h3("Detailed ranking"), + div(class = "p-1"), + DT::dataTableOutput("selected_genes") ) ) ),