@@ -224,64 +224,80 @@ app_server <- function(input, output, session) {
224224 })
225225
226226 static_gene <- reactive({
227- p <- vis_gene(
228- spe ,
229- sampleid = input $ sample ,
230- geneid = input $ geneid ,
231- multi_gene_method = input $ multi_gene_method ,
232- assayname = input $ assayname ,
233- minCount = input $ minCount ,
234- cont_colors = cont_colors(),
235- image_id = input $ imageid ,
236- alpha = input $ alphalevel ,
237- point_size = input $ pointsize ,
238- auto_crop = input $ auto_crop ,
239- is_stitched = is_stitched
240- )
241- if (! input $ side_by_side_gene ) {
242- return (p )
243- } else {
244- p_no_spots <- p
245- p_no_spots $ layers [[2 ]] <- NULL
246-
247- p_no_spatial <- p
248- p_no_spatial $ layers [[1 ]] <- NULL
249- cowplot :: plot_grid(
250- plotlist = list (
251- p_no_spots ,
252- p_no_spatial + ggplot2 :: theme(legend.position = " none" )
253- ),
254- nrow = 1 ,
255- ncol = 2
227+ gene_warning = NULL
228+ withCallingHandlers({
229+ p <- vis_gene(
230+ spe ,
231+ sampleid = input $ sample ,
232+ geneid = input $ geneid ,
233+ multi_gene_method = input $ multi_gene_method ,
234+ assayname = input $ assayname ,
235+ minCount = input $ minCount ,
236+ cont_colors = cont_colors(),
237+ image_id = input $ imageid ,
238+ alpha = input $ alphalevel ,
239+ point_size = input $ pointsize ,
240+ auto_crop = input $ auto_crop ,
241+ is_stitched = is_stitched
256242 )
257- }
243+ if (! input $ side_by_side_gene ) {
244+ p_result = p
245+ } else {
246+ p_no_spots <- p
247+ p_no_spots $ layers [[2 ]] <- NULL
248+
249+ p_no_spatial <- p
250+ p_no_spatial $ layers [[1 ]] <- NULL
251+ p_result = cowplot :: plot_grid(
252+ plotlist = list (
253+ p_no_spots ,
254+ p_no_spatial + ggplot2 :: theme(legend.position = " none" )
255+ ),
256+ nrow = 1 ,
257+ ncol = 2
258+ )
259+ }
260+ }, warning = function (w ) {
261+ gene_warning <<- conditionMessage(w )
262+ invokeRestart(" muffleWarning" )
263+ })
264+ return (list (p = p_result , gene_warning = gene_warning ))
258265 })
259266
260267 static_gene_grid <- reactive({
261268 input $ gene_grid_update
262269
263- plots <-
264- vis_grid_gene(
265- spe ,
266- geneid = isolate(input $ geneid ),
267- multi_gene_method = input $ multi_gene_method ,
268- assayname = isolate(input $ assayname ),
269- minCount = isolate(input $ minCount ),
270- return_plots = TRUE ,
271- spatial = isolate(input $ grid_spatial_gene ),
272- cont_colors = isolate(cont_colors()),
273- image_id = isolate(input $ imageid ),
274- alpha = isolate(input $ alphalevel ),
275- point_size = isolate(input $ pointsize ),
276- sample_order = isolate(input $ gene_grid_samples ),
277- auto_crop = isolate(input $ auto_crop ),
278- is_stitched = is_stitched
279- )
280- cowplot :: plot_grid(
270+ gene_grid_warnings = NULL
271+ withCallingHandlers({
272+ plots <-
273+ vis_grid_gene(
274+ spe ,
275+ geneid = isolate(input $ geneid ),
276+ multi_gene_method = input $ multi_gene_method ,
277+ assayname = isolate(input $ assayname ),
278+ minCount = isolate(input $ minCount ),
279+ return_plots = TRUE ,
280+ spatial = isolate(input $ grid_spatial_gene ),
281+ cont_colors = isolate(cont_colors()),
282+ image_id = isolate(input $ imageid ),
283+ alpha = isolate(input $ alphalevel ),
284+ point_size = isolate(input $ pointsize ),
285+ sample_order = isolate(input $ gene_grid_samples ),
286+ auto_crop = isolate(input $ auto_crop ),
287+ is_stitched = is_stitched
288+ )
289+ }, warning = function (w ) {
290+ gene_grid_warnings <<- c(gene_grid_warnings , conditionMessage(w ))
291+ invokeRestart(" muffleWarning" )
292+ })
293+
294+ p_result = cowplot :: plot_grid(
281295 plotlist = plots ,
282296 nrow = isolate(input $ gene_grid_nrow ),
283297 ncol = isolate(input $ gene_grid_ncol )
284298 )
299+
300+ return (list (p = p_result , gene_grid_warnings = gene_grid_warnings ))
285301 })
286302
287303 editImg_manipulations <- reactive({
@@ -439,7 +455,7 @@ app_server <- function(input, output, session) {
439455 height = 8 ,
440456 width = 8 * ifelse(input $ side_by_side_gene , 2 , 1 )
441457 )
442- print(static_gene())
458+ print(static_gene()[[ ' p ' ]] )
443459 dev.off()
444460 }
445461 )
@@ -467,7 +483,7 @@ app_server <- function(input, output, session) {
467483 height = 8 * isolate(input $ gene_grid_nrow ),
468484 width = 8 * isolate(input $ gene_grid_ncol )
469485 )
470- print(static_gene_grid())
486+ print(static_gene_grid()[[ ' p ' ]] )
471487 dev.off()
472488 }
473489 )
@@ -530,17 +546,32 @@ app_server <- function(input, output, session) {
530546 height = " auto"
531547 )
532548
533-
534549 output $ gene <- renderPlot(
535550 {
536- static_gene()
551+ static_gene()[[ ' p ' ]]
537552 },
538553 width = function () {
539554 600 * ifelse(input $ side_by_side_gene , 2 , 1 )
540555 },
541556 height = 600
542557 )
543558
559+ output $ gene_warnings <- renderText({
560+ # Since 'static_gene()' is invoked twice (once also in the assignment
561+ # of 'output$gene'), we silence any errors that occur in this second
562+ # invocation to not duplicate error messages
563+ this_warning = NULL
564+ temp = try(
565+ { this_warning = static_gene()[[' gene_warning' ]] }, silent = TRUE
566+ )
567+
568+ if (! is.null(this_warning )) {
569+ paste(" Warning:" , this_warning )
570+ } else {
571+ " "
572+ }
573+ })
574+
544575
545576 output $ gene_grid_static <- renderUI({
546577 input $ gene_grid_update
@@ -554,12 +585,29 @@ app_server <- function(input, output, session) {
554585
555586 output $ gene_grid <- renderPlot(
556587 {
557- print(static_gene_grid())
588+ print(static_gene_grid()[[ ' p ' ]] )
558589 },
559590 width = " auto" ,
560591 height = " auto"
561592 )
562593
594+ output $ gene_grid_warnings <- renderText({
595+ # Since 'static_gene_grid()' is invoked twice (once also in the
596+ # assignment of 'output$gene_grid'), we silence any errors that occur
597+ # in this second invocation to not duplicate error messages
598+ these_warnings = NULL
599+ temp = try(
600+ { these_warnings = static_gene_grid()[[' gene_grid_warnings' ]] },
601+ silent = TRUE
602+ )
603+
604+ if (! is.null(these_warnings )) {
605+ paste(" Warnings:" , paste(these_warnings , collapse = " ; " ))
606+ } else {
607+ " "
608+ }
609+ })
610+
563611 output $ editImg_plot <- renderPlot(
564612 {
565613 plot(editImg_manipulations())
0 commit comments