Skip to content

Commit

Permalink
select_group_ui/server works!
Browse files Browse the repository at this point in the history
See dreamRs/datamods#63 for differences in how this works in modularized code. Not intuitive.
  • Loading branch information
johnsonra committed Dec 4, 2023
1 parent cb9b2eb commit c2a3c85
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Imports:
briKmeans,
bslib,
cowplot,
datamods,
DBI,
dplyr,
foreach,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ importFrom(briKmeans,kma.similarity)
importFrom(bslib,card)
importFrom(bslib,card_header)
importFrom(cowplot,theme_cowplot)
importFrom(datamods,select_group_server)
importFrom(datamods,select_group_ui)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
Expand Down
39 changes: 33 additions & 6 deletions R/qc_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
#' @name qc_tab
#'
#' @param id Shiny namespace ID
#' @param con Active DBI database connection
#' @param user Username of the user
#'
#' @return A modularized tagList
#' @export
#' @importFrom shiny NS
#' @importFrom shiny numericInput
#' @importFrom shiny sliderInput
#' @importFrom shiny tagList
qc_sidebarUI <- function(id)
#'
#' @importFrom datamods select_group_ui
qc_sidebarUI <- function(id, con, user)
{
ns <- NS(id)

tagList(
select_group_ui(id = ns("qc_channels"),
params = list(list(inputId = "expID", label = "Experiment"),
list(inputId = "sID", label = "Sample"),
list(inputId = "chanID", label = "Channel")),
inline = FALSE),
sliderInput(ns('qc_min_track_len'), 'Minimum Track Length', 3, 60, value = 6), # minimum track length in minutes
numericInput(ns('qc_n_cells'), 'Number of cells', value = 100)
)
Expand All @@ -36,6 +45,8 @@ qc_sidebarUI <- function(id)
#' @importFrom bslib card
#' @importFrom bslib card_header
#'
#' @importFrom datamods select_group_ui
#'
#' @importFrom shiny NS
#' @importFrom shiny plotOutput
#' @importFrom shiny tagList
Expand All @@ -55,10 +66,9 @@ qc_cardsUI <- function(id)
#'
#' @rdname qc_tab
#'
#' @param con Active DBI database connection
#' @param user Username of the user
#'
#' @export
#' @importFrom datamods select_group_server
#'
#' @importFrom dplyr arrange
#' @importFrom dplyr group_by
#' @importFrom dplyr mutate
Expand All @@ -84,6 +94,19 @@ qc_server <- function(id, con, user)
id,
function(input, output, session)
{
ns <- NS(id)

# pull available channels
chanSum <- reactive({
get_dat(con,
user = user,
select = 'expID, chanID, sID, treatment',
from = 'chanSummary') %>%
mutate(expID = factor(expID),
chanID = factor(chanID),
sID = factor(sID))
})

# pull raw track information
trackRaw <- reactive({
get_dat(con,
Expand All @@ -92,6 +115,12 @@ qc_server <- function(id, con, user)
from = 'trackRaw',
where = 'chanID=2')
})

# for channel/sample selection
selection <- select_group_server(id = "qc_channels",
data_r = chanSum,
vars_r = reactive(c('expID', 'sID', 'chanID'))
)

output$qc_track_len <- renderPlot({
group_by(trackRaw(), trackID) %>%
Expand All @@ -114,8 +143,6 @@ qc_server <- function(id, con, user)

mutate(time = frames / 2)

print(tmp)

ggplot(tmp, aes(time, n_tracks)) +
geom_line() +
labs(x = 'Time (min)', y = '# Tracks')
Expand Down
2 changes: 1 addition & 1 deletion man/qc_tab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions shiny/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ library(shiny)
library(shinymanager)
library(RSQLite)
library(DBI)
library(config)
library(bslib)

library(ggplot2)
Expand Down Expand Up @@ -74,5 +73,3 @@ server <- function(input, output, session) {
#######

shinyApp(ui = ui, server = server)

dbDisconnect(con)

0 comments on commit c2a3c85

Please sign in to comment.