Skip to content

Commit

Permalink
updated subset cell functionality to all plots
Browse files Browse the repository at this point in the history
  • Loading branch information
jfouyang committed Jul 6, 2021
1 parent 2f3e731 commit 71111ad
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 197 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: ShinyCell
Type: Package
Title: Shiny Interactive Web Apps for Single-Cell Data
Version: 2.0.0
Version: 2.1.0
Author: John F. Ouyang
Maintainer: John F. Ouyang <john.f.ouyang@gmail.com>
Description: Shiny apps for interactive exploration of single-cell data
Expand Down
7 changes: 6 additions & 1 deletion R/makeShinyApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#' page, year, doi, link. See example below.
#' @param shiny.dir specify directory to create the shiny app in. Default is
#' to create a new directory named "shinyApp"
#' @param enableSubset specify whether to enable "Toggle to subset cells"
#' functionality in the shiny app. Default is to enable this functionality
#' @param defPtSiz specify default point size for single cells. For example, a
#' smaller size can be used if you have many cells in your dataset
#' @param ganalytics Google analytics tracking ID (e.g. "UA-123456789-0")
#' @param default.gene1 specify primary default gene to show
#' @param default.gene2 specify secondary default gene to show
Expand Down Expand Up @@ -71,7 +75,7 @@ makeShinyApp <- function(
obj, scConf, gex.assay = NA, gex.slot = c("data", "scale.data", "counts"),
gene.mapping = FALSE,
shiny.title = "scRNA-seq shiny app", shiny.footnotes = "",
shiny.dir = "shinyApp/", ganalytics = NA,
shiny.dir = "shinyApp/", enableSubset = TRUE, defPtSiz = 1.25, ganalytics=NA,
default.gene1 = NA, default.gene2 = NA, default.multigene = NA,
default.dimred = NA){

Expand All @@ -84,6 +88,7 @@ makeShinyApp <- function(
default.gene1, default.gene2, default.multigene, default.dimred)
makeShinyCodes(shiny.title = shiny.title, shiny.footnotes = shiny.footnotes,
shiny.prefix = "sc1", shiny.dir = shiny.dir,
enableSubset = enableSubset, defPtSiz = defPtSiz,
ganalytics = ganalytics)

}
Expand Down
20 changes: 15 additions & 5 deletions R/makeShinyCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' page, year, doi, link. See example below.
#' @param shiny.prefix specify file prefix
#' @param shiny.dir specify directory to create the shiny app in
#' @param enableSubset specify whether to enable "Toggle to subset cells"
#' functionality in the shiny app. Default is to enable this functionality
#' @param defPtSiz specify default point size for single cells. For example, a
#' smaller size can be used if you have many cells in your dataset
#' @param ganalytics Google analytics tracking ID (e.g. "UA-123456789-0")
#'
#' @return server.R and ui.R required for shiny app
Expand All @@ -37,7 +41,13 @@
#'
#' @export
makeShinyCodes <- function(shiny.title, shiny.footnotes,
shiny.prefix, shiny.dir, ganalytics = NA){
shiny.prefix, shiny.dir,
enableSubset = TRUE, defPtSiz = 1.25,
ganalytics = NA){
subst = "#"
if(enableSubset){subst = ""}
defPtSiz = as.character(defPtSiz)

if(packageVersion("readr") >= "1.4.0"){
### Write code for server.R
fname = paste0(shiny.dir, "/server.R")
Expand All @@ -46,7 +56,7 @@ makeShinyCodes <- function(shiny.title, shiny.footnotes,
"ggrepel","hdf5r","ggdendro","gridExtra")), file = fname)
readr::write_file(wrSVload(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrSVfix(), append = TRUE, file = fname)
readr::write_file(wrSVmain(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrSVmain(shiny.prefix, subst), append = TRUE, file = fname)
readr::write_file(wrSVend(), append = TRUE, file = fname)


Expand All @@ -56,7 +66,7 @@ makeShinyCodes <- function(shiny.title, shiny.footnotes,
c("shiny","shinyhelper","data.table","Matrix","DT","magrittr")), file = fname)
readr::write_file(wrUIload(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrUIsingle(shiny.title, ganalytics), append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix), append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix, subst, defPtSiz), append = TRUE, file = fname)
readr::write_file(glue::glue(', \n'), append = TRUE, file = fname)
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, file = fname)

Expand All @@ -75,7 +85,7 @@ makeShinyCodes <- function(shiny.title, shiny.footnotes,
"ggrepel","hdf5r","ggdendro","gridExtra")), path = fname)
readr::write_file(wrSVload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVfix(), append = TRUE, path = fname)
readr::write_file(wrSVmain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrSVmain(shiny.prefix, subst), append = TRUE, path = fname)
readr::write_file(wrSVend(), append = TRUE, path = fname)


Expand All @@ -85,7 +95,7 @@ makeShinyCodes <- function(shiny.title, shiny.footnotes,
c("shiny","shinyhelper","data.table","Matrix","DT","magrittr")), path = fname)
readr::write_file(wrUIload(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrUIsingle(shiny.title, ganalytics), append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix), append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix, subst, defPtSiz), append = TRUE, path = fname)
readr::write_file(glue::glue(', \n'), append = TRUE, path = fname)
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)

Expand Down
25 changes: 20 additions & 5 deletions R/makeShinyCodesMulti.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#' @param shiny.headers specify the tab header names for each dataset. Length
#' must match that of \code{shiny.prefix}
#' @param shiny.dir specify directory to create the shiny app in
#' @param enableSubset specify whether to enable "Toggle to subset cells"
#' functionality in the shiny app. Default is to enable this functionality
#' @param defPtSiz specify default point size for single cells. For example, a
#' smaller size can be used if you have many cells in your dataset. A single
#' value can be specified to set the point size for all datasets. Otherwise,
#' users have to specify one value for each dataset
#' @param ganalytics Google analytics tracking ID (e.g. "UA-123456789-0")
#'
#' @return server.R and ui.R required for shiny app
Expand All @@ -36,18 +42,25 @@
#' doi = "10.1038/s41586-020-2734-6",
#' link = "https://www.nature.com/articles/s41586-020-2734-6")
#' makeShinyCodes(shiny.title = "scRNA-seq shiny app", shiny.footnotes = "",
#' shiny.prefix = c("sc1", "sc2"),
#' shiny.prefix = c("sc1", "sc2"), defPtSiz = c(1.25, 1.5),
#' shiny.headers = c("dataset1", "dataset2"),
#' shiny.dir = "shinyApp/")
#'
#' @export
makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
shiny.prefix, shiny.headers, shiny.dir,
enableSubset = TRUE, defPtSiz = 1.25,
ganalytics = NA){
### Checks
if(length(shiny.prefix) != length(shiny.headers)){
stop("length of shiny.prefix and shiny.headers does not match!")
}
subst = "#"
if(enableSubset){subst = ""}
if(length(shiny.prefix) != length(defPtSiz)){
defPtSiz = rep(defPtSiz[1], length(shiny.prefix))
}
defPtSiz = as.character(defPtSiz)

if(packageVersion("readr") >= "1.4.0"){
### Write code for server.R
Expand All @@ -60,7 +73,7 @@ makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
}
readr::write_file(wrSVfix(), append = TRUE, file = fname)
for(i in shiny.prefix){
readr::write_file(wrSVmain(i), append = TRUE, file = fname)
readr::write_file(wrSVmain(i, subst), append = TRUE, file = fname)
}
readr::write_file(wrSVend(), append = TRUE, file = fname)

Expand All @@ -77,7 +90,8 @@ makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
hhh = shiny.headers[i]
readr::write_file(glue::glue('navbarMenu("{hhh}",'),
append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix[i]), append = TRUE, file = fname)
readr::write_file(wrUImain(shiny.prefix[i], subst, defPtSiz[i]),
append = TRUE, file = fname)
readr::write_file(glue::glue('), \n\n\n'), append = TRUE, file = fname)
}
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, file = fname)
Expand All @@ -100,7 +114,7 @@ makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
}
readr::write_file(wrSVfix(), append = TRUE, path = fname)
for(i in shiny.prefix){
readr::write_file(wrSVmain(i), append = TRUE, path = fname)
readr::write_file(wrSVmain(i, subst), append = TRUE, path = fname)
}
readr::write_file(wrSVend(), append = TRUE, path = fname)

Expand All @@ -117,7 +131,8 @@ makeShinyCodesMulti <- function(shiny.title, shiny.footnotes,
hhh = shiny.headers[i]
readr::write_file(glue::glue('navbarMenu("{hhh}",'),
append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix[i]), append = TRUE, path = fname)
readr::write_file(wrUImain(shiny.prefix[i], subst, defPtSiz[i]),
append = TRUE, path = fname)
readr::write_file(glue::glue('), \n\n\n'), append = TRUE, path = fname)
}
readr::write_file(wrUIend(shiny.footnotes), append = TRUE, path = fname)
Expand Down
Loading

0 comments on commit 71111ad

Please sign in to comment.