Skip to content

Commit

Permalink
general cleanup, and polishing a bit what is there so far
Browse files Browse the repository at this point in the history
  • Loading branch information
federicomarini committed Oct 2, 2024
1 parent ff5eb34 commit 08cd8fe
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 477 deletions.
233 changes: 51 additions & 182 deletions R/iSEEindex.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,74 @@
#' states prepared by the app maintainer.
#'
#' @section Data Sets:
#' The function passed to the argument `FUN.datasets` must return a `list` that contains metadata about the available data sets.
#' The function passed to the argument `FUN.datasets` must return a `list` that
#' contains metadata about the available data sets.
#'
#' For each data set, required metadata are:
#'
#' \describe{
#' \item{id}{A unique identifier for the data set.}
#' \item{title}{A short human-readable title for the data set, displayed in the 'Info' panel when the data set is selected.}
#' \item{uri}{A Uniform Resource Identifier (URI) that indicates the location of the data file that contains the data set.}
#' \item{description}{A more detailed description of the data set, displayed in the 'Info' panel when the data set is selected.}
#' \item{title}{A short human-readable title for the data set, displayed in the
#' 'Info' panel when the data set is selected.}
#' \item{uri}{A Uniform Resource Identifier (URI) that indicates the location of
#' the data file that contains the data set.}
#' \item{description}{A more detailed description of the data set, displayed in
#' the 'Info' panel when the data set is selected.}
#' }
#'
#' Example:
#'
#' ```
#' list(
#' list(
#' id = "dataset01",
#' title = "Dataset 01",
#' uri = "https://example.com/1.rds",
#' description = "My first data set."
#' id = "dataset01",
#' title = "Dataset 01",
#' uri = "https://example.com/1.rds",
#' description = "My first data set."
#' ),
#' list(
#' id = "dataset02",
#' title = "Dataset 02",
#' uri = "https://example.com/1.rds",
#' description = "My second data set."
#' id = "dataset02",
#' title = "Dataset 02",
#' uri = "https://example.com/1.rds",
#' description = "My second data set."
#' )
#' )
#' ```
#'
#' The individual sub-lists may also contain optional named metadata specific to individual [`iSEEindexResource-class`] classes (refer to the help page of those classes for details).
#' The individual sub-lists may also contain optional named metadata specific to
#' individual [`iSEEindexResource-class`] classes (refer to the help page of
#' those classes for details).
#'
#' **Important**: The `id` value is used to identify the data set file in the \pkg{BiocFileCache}.
#' Thus, we recommend using a dedicated `BiocFileCache()` for the app, using the `BiocFileCache(cache)` argument to specify an on-disk location (directory path) for the dedicated cache.
#' **Important**: The `id` value is used to identify the data set file in the
#' \pkg{BiocFileCache}.
#' Thus, we recommend using a dedicated `BiocFileCache()` for the app, using the
#' `BiocFileCache(cache)` argument to specify an on-disk location (directory
#' path) for the dedicated cache.
#'
#' @section Initial Configurations:
#' The function passed to the argument `FUN.initial` must return a `list` that contains metadata about the available initial configurations, or `NULL` in the absence of any custom initial configuration (default settings will be applied to all data sets.).
#' The function passed to the argument `FUN.initial` must return a `list` that
#' contains metadata about the available initial configurations, or `NULL` in
#' the absence of any custom initial configuration (default settings will be
#' applied to all data sets.).
#'
#' For each initial configuration, required metadata are:
#'
#' \describe{
#' \item{id}{A unique identifier for the initial configuration.}
#' \item{title}{A short human-readable title for the initial configuration, representing the initial configuration in the 'Initial settings' dropdown menu.}
#' \item{uri}{A Uniform Resource Identifier (URI) that indicates the location of the R script that contains the initial configuration.}
#' \item{description}{A more detailed description of the initial configuration, displayed in the 'Configure and launch' panel when the initial configuration is selected.}
#' \item{title}{A short human-readable title for the initial configuration,
#' representing the initial configuration in the 'Initial settings' dropdown menu.}
#' \item{uri}{A Uniform Resource Identifier (URI) that indicates the location of
#' the R script that contains the initial configuration.}
#' \item{description}{A more detailed description of the initial configuration,
#' displayed in the 'Configure and launch' panel when the initial configuration
#' is selected.}
#' }
#'
#' For each initial configuration, optional metadata are:
#' \describe{
#' \item{datasets}{A series of data set identifiers for which the configuration should be made available. If missing, the configuration will be available for all data sets.}
#' \item{datasets}{A series of data set identifiers for which the configuration
#' should be made available. If missing, the configuration will be available for
#' all data sets.}
#' }
#'
#' Example:
Expand All @@ -78,7 +96,9 @@
#' )
#' ```
#'
#' The individual sub-lists may also contain additional optional named metadata specific to individual [`iSEEindexResource-class`] classes (refer to the help page of those classes for details).
#' The individual sub-lists may also contain additional optional named metadata
#' specific to individual [`iSEEindexResource-class`] classes (refer to the help
#' page of those classes for details).
#'
#' @param bfc An [BiocFileCache()] object.
#' @param FUN.datasets A function that returns a `list` of metadata for
Expand All @@ -97,7 +117,8 @@
#' @param body.header UI element to display \emph{above} the main landing page body.
#' @param body.footer UI element to display \emph{below} the main landing page body.
#'
#' @return An [iSEE::iSEE()] app with a custom landing page using a [BiocFileCache()] to cache a selection of data sets.
#' @return An [iSEE::iSEE()] app with a custom landing page using a
#' [BiocFileCache()] to cache a selection of data sets.
#'
#' @author Kevin Rue-Albrecht
#'
Expand Down Expand Up @@ -192,107 +213,19 @@ iSEEindex <- function(bfc,
}

iSEE(
landingPage = .landing_page(bfc,
FUN.datasets,
FUN.initial,
default.add,
default.position,
body.header,
body.footer
landingPage = .landing_page(
bfc,
FUN.datasets,
FUN.initial,
default.add,
default.position,
body.header,
body.footer
),
appTitle = app.title
)
}

#### #' @examples
#### #' ##
#### #' ##
#### #'
#### #' library(BiocFileCache)
#### #' bfc <- BiocFileCache(cache = tempdir())
#### #'
#### #' ##
#### #' ##
#### #'
#### #' dataset_fun <- function() {
#### #' x <- yaml::read_yaml(
#### #' system.file("tonsils_example", "tonsil_package.yml", package = "iSEEindex")
#### #' )
#### #' x$datasets
#### #' }
#### #'
#### #' initial_fun <- function() {
#### #' x <- yaml::read_yaml(
#### #' system.file("tonsils_example", "tonsil_package.yml", package = "iSEEindex")
#### #' )
#### #' x$initial
#### #' }
#### #'
#### #' library("shiny")
#### #' header_tonsils <- fluidRow(
#### #' shinydashboard::box(
#### #' width = 12,
#### #' collapsible = TRUE,
#### #' collapsed = TRUE,
#### #' title = "How to explore the Tonsil Atlas datasets",
#### #' includeMarkdown(
#### #' system.file("tonsils_example", "header_tonsils.md", package = "iSEEindex")
#### #' )
#### #' )
#### #' )
#### #'
#### #' footer_tonsils <- fluidRow(
#### #' shinydashboard::box(
#### #' width = 12,
#### #' includeMarkdown(
#### #' system.file("tonsils_example", "footer_tonsils.md", package = "iSEEindex")
#### #' )
#### #' )
#### #' )
#### #'
#### #' app <- iSEEindex_runr(bfc, dataset_fun, initial_fun,
#### #' default.add = TRUE,
#### #' default.position = "last",
#### #' app.title = "iSEE ❤️ Tonsil Data Atlas",
#### #' body.header = header_tonsils,
#### #' body.footer = footer_tonsils)
#### #'
#### #' if (interactive()) {
#### #' shiny::runApp(app, port = 1234)
#### #' }
#### # iSEEindex_runr <- function(bfc,
#### # FUN.datasets,
#### # FUN.initial = NULL,
#### # default.add = TRUE,
#### # default.position = c("first", "last"),
#### # app.title = NULL,
#### # body.header = NULL,
#### # body.footer = NULL) {
#### # stopifnot(is(bfc, "BiocFileCache"))
#### # if (is.null(FUN.initial)) {
#### # FUN.initial <- function() NULL
#### # }
#### #
#### # if (is.null(app.title)) {
#### # app.title <- sprintf("iSEEindex - v%s",
#### # packageVersion("iSEEindex"))
#### # } else {
#### # app.title <- app.title
#### # }
#### #
#### # iSEE(
#### # landingPage=.landing_page(bfc,
#### # FUN.datasets,
#### # FUN.initial,
#### # default.add, default.position,
#### # body.header,
#### # body.footer,
#### # already_se_object = TRUE),
#### # appTitle = app.title
#### # )
#### # }



#' Prepare and Launch the Main App.
#'
Expand Down Expand Up @@ -386,67 +319,3 @@ iSEEindex <- function(bfc,
# nocov end
}






# .launch_isee_runr <- function(FUN, bfc, session, pObjects) {
# # nocov start
# dataset_id <- pObjects[[.dataset_selected_id]]
# which_dataset <- which(pObjects$datasets_table[[.datasets_id]] == dataset_id)
# # TODO: refactor as function that takes data set identifier and returns uri
# dataset_metadata <- as.list(pObjects$datasets_table[which_dataset, , drop=FALSE])
# # TODO: refactor as function that takes data set identifier and returns title
# dataset_title <- pObjects$datasets_table[which_dataset, .datasets_title, drop=TRUE]
# withProgress(message = sprintf("Loading '%s'", dataset_title),
# value = 0, max = 2, {
# incProgress(1, detail = "(Down)loading object")
# se2 <- try(.load_sce(bfc, dataset_id, dataset_metadata, already_se_object = TRUE))
# incProgress(1, detail = "Launching iSEE app")
# if (is(se2, "try-error")) {
# showNotification("Invalid SummarizedExperiment supplied.", type="error")
# } else {
# if (is.null(pObjects$initial_table)) {
# initial <- NULL
# tour <- NULL
# } else {
# initial_id <- pObjects[[.ui_initial]]
# which_initial <- which(
# pObjects$initial_table[[.initial_config_id]] == initial_id &
# pObjects$initial_table[[.initial_datasets_id]] == dataset_id
# )
# initial_metadata <- as.list(pObjects$initial_table[which_initial, , drop = FALSE])
# initial_message <- capture.output(
# init <- try(.parse_initial(bfc, dataset_id, initial_id, initial_metadata)),
# type = "message")
# initial <- init$initial
# tour <- init$tour
# }
# if (is(init, "try-error")) {
# showModal(modalDialog(
# title = "Invalid initial state",
# p("An error occured while evaluating the script:"),
# markdown(paste0(c("```", initial_message, "```"), collapse = "\n")),
# p("Contact the app maintainer for further help."),
# footer = NULL,
# size = "l",
# easyClose = TRUE
# ))
# return(NULL)
# }
# FUN(SE=se2, INITIAL=initial, TOUR=tour)
# shinyjs::enable(iSEE:::.generalOrganizePanels) # organize panels
# shinyjs::enable(iSEE:::.generalLinkGraph) # link graph
# shinyjs::enable(iSEE:::.generalExportOutput) # export content
# shinyjs::enable(iSEE:::.generalCodeTracker) # tracked code
# shinyjs::enable(iSEE:::.generalPanelSettings) # panel settings
# shinyjs::enable(iSEE:::.generalVignetteOpen) # open vignette
# shinyjs::enable(iSEE:::.generalSessionInfo) # session info
# shinyjs::enable(iSEE:::.generalCitationInfo) # citation info
# }
# }, session = session)
#
# invisible(NULL)
# # nocov end
# }
Loading

0 comments on commit 08cd8fe

Please sign in to comment.