mirror of
				https://github.com/johrpan/ubigen.git
				synced 2025-10-26 19:57:24 +01:00 
			
		
		
		
	Add score distribution plot
This commit is contained in:
		
							parent
							
								
									276730f217
								
							
						
					
					
						commit
						1a47b30dbf
					
				
					 3 changed files with 55 additions and 1 deletions
				
			
		|  | @ -23,5 +23,6 @@ Imports: | |||
|     bslib, | ||||
|     data.table, | ||||
|     DT, | ||||
|     plotly, | ||||
|     glue, | ||||
|     shiny | ||||
|  |  | |||
							
								
								
									
										43
									
								
								R/server.R
									
										
									
									
									
								
							
							
						
						
									
										43
									
								
								R/server.R
									
										
									
									
									
								
							|  | @ -21,9 +21,52 @@ server <- function(input, output) { | |||
|         data | ||||
|     }) | ||||
| 
 | ||||
|     output$scores_plot <- plotly::renderPlotly(scores_plot(ranked_data())) | ||||
|     output$ranked_data <- DT::renderDataTable(genes_table(ranked_data())) | ||||
| } | ||||
| 
 | ||||
| #' Create plot showing the distribution of scores using `plotly`. | ||||
| #' | ||||
| #' @param ranked_data Data on genes with precomputed ranks. | ||||
| #' @param ranks How may ranks the x-axis should include. If this parameter is | ||||
| #'   `NULL`, all ranks will be shown. | ||||
| #' | ||||
| #' @return A `plotly` figure for rendering. | ||||
| #' @noRd | ||||
| scores_plot <- function(ranked_data, ranks = 1000) { | ||||
|     data <- if (is.null(ranks)) { | ||||
|         ranked_data | ||||
|     } else { | ||||
|         ranked_data[1:ranks] | ||||
|     } | ||||
| 
 | ||||
|     ranks_label <- if (is.null(ranks)) { | ||||
|         "Ranks" | ||||
|     } else { | ||||
|         glue::glue("Ranks (1 to {ranks})") | ||||
|     } | ||||
| 
 | ||||
|     plotly::plot_ly() |> | ||||
|         plotly::add_markers( | ||||
|             data = data, | ||||
|             x = ~rank, | ||||
|             y = ~score, | ||||
|             text = ~hgnc_name, | ||||
|             customdata = ~percentile, | ||||
|             hovertemplate = paste0( | ||||
|                 "<b>%{text}</b><br>", | ||||
|                 "Rank: %{x}<br>", | ||||
|                 "Score: %{y:.2}<br>", | ||||
|                 "Percentile: %{customdata:.2%}", | ||||
|                 "<extra></extra>" | ||||
|             ) | ||||
|         ) |> | ||||
|         plotly::layout( | ||||
|             xaxis = list(title = ranks_label), | ||||
|             yaxis = list(title = "Score") | ||||
|         ) | ||||
| } | ||||
| 
 | ||||
| #' Create a displayable data table from the gene results data. | ||||
| #' @noRd | ||||
| genes_table <- function(data) { | ||||
|  |  | |||
							
								
								
									
										12
									
								
								R/ui.R
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								R/ui.R
									
										
									
									
									
								
							|  | @ -41,7 +41,17 @@ ui <- function() { | |||
|                 ), | ||||
|                 mainPanel( | ||||
|                     width = 9, | ||||
|                     DT::dataTableOutput("ranked_data") | ||||
|                     tabsetPanel( | ||||
|                         type = "pills", | ||||
|                         tabPanel( | ||||
|                             title = "Distribution of scores", | ||||
|                             plotly::plotlyOutput("scores_plot") | ||||
|                         ), | ||||
|                         tabPanel( | ||||
|                             title = "Detailed results", | ||||
|                             DT::dataTableOutput("ranked_data") | ||||
|                         ) | ||||
|                     ) | ||||
|                 ) | ||||
|             ) | ||||
|         ), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue