amc-heme / scExploreR

Shiny app for single cell omics data visualization
https://amc-heme.github.io/scExploreR/
MIT License
2 stars 0 forks source link

Scatterplot in plots tab has an error when used with non-default palettes #199

Closed wish1832 closed 1 year ago

wish1832 commented 1 year ago

When attempting to plot a scatterplot in the plots tab using a non-default palette, the error below is returned. When the default categorical palette is selected, the error disappears.

Warning: Error in palette: invalid argument type
  173: <Anonymous>
  172: stop
  171: plot
  170: renderPlot [/Users/billshowers/Dropbox/1A_Jordan_Lab/Projects/scExploreR_files/scExploreR/R/module-plot_module.R#2972]
  168: func
  128: drawPlot
  114: <reactive:plotObj>
   98: drawReactive
   85: renderFunc
   84: output$d0_d30_plots-scatter-plot
    3: runApp
    2: print.shiny.appobj
    1: <Anonymous>
wish1832 commented 1 year ago

This error was due to improper syntax in the code passing the palette to Seurat::FeatureScatter:

FeatureScatter(
      object, 
      feature1 = feature_1,
      feature2 = feature_2,
      group.by = group_by,
      # Cols: use user defined palette, or the defaults if palette() == NULL 
      cols = 
        if (!is.null(palette)){
          # colorRampPalette() extends or contracts the given palette to 
          # produce exactly the required number of colors
          colorRampPalette(palette(n_colors))
          # Use ggplot2 defaults if palette() is unspecified
        } else NULL, 
      )

colorRampPalette(palette(n_colors)) should be colorRampPalette(palette)(n_colors). colorRampPalette creates a function from the palette passed to it, which n_colors is passed to to create a new palette to "stretch" or "shrink" the number of colors to match the number needed based on the number of group by categories.

palette is a vector of hex codes, so it must be passed as an argument to colorRampPalette(). If called as a function, it will result in the error returned.

The erroneous line of code is only ran when palette is not equal to NULL, which is why the error does not result when the default palette is passed.

wish1832 commented 1 year ago

This was fixed with the merge of #200.