Commit b35e5fab authored by Kunst, Jonathan's avatar Kunst, Jonathan
Browse files

Major addition of golem style app that has same functionality as previous app.r

parent f7ebb6a5
^.*\.Rproj$
^\.Rproj\.user$
^data-raw$
dev_history.R
^dev$
$run_dev.*
^README\.Rmd$
^CODE_OF_CONDUCT\.md$
^doc$
^Meta$
inst/doc
/doc/
/Meta/
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards
of acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies
when an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at [INSERT CONTACT
METHOD]. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0,
available at https://www.contributor-covenant.org/version/2/0/
code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://
www.contributor-covenant.org/translations.
Package: polyqtlvis
Title: Polyploid QTL Visualisation
Version: 0.0.0.9000
Authors@R: person('Jonathan', 'Kunst', email = 'jonathankunst@gmail.com', role = c('cre', 'aut'))
Description: Shiny application for polyploid QTL visualisation.
License: GPL-3
Imports:
attempt,
config (>= 0.3.1),
DT,
glue,
golem (>= 0.3.1),
htmltools,
parallel,
polyqtlR,
processx,
readr,
shiny (>= 1.7.1),
tools
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
URL: https://git.wageningenur.nl/jonathan.kunst/polyploid-datavisualisation
BugReports: https://git.wageningenur.nl/jonathan.kunst/polyploid-datavisualisation/issues
Suggests:
rmarkdown,
knitr,
spelling,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Language: en-US
VignetteBuilder: knitr
# Generated by roxygen2: do not edit by hand
export(run_app)
import(shiny)
importFrom(golem,activate_js)
importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,with_golem_options)
importFrom(parallel,detectCores)
importFrom(polyqtlR,estimate_IBD)
importFrom(polyqtlR,visualiseHaplo)
importFrom(readr,read_csv)
importFrom(readr,read_rds)
importFrom(shiny,NS)
importFrom(shiny,shinyApp)
importFrom(shiny,tagList)
importFrom(shiny,validate)
importFrom(tools,file_ext)
# polyqtlvis 0.0.0.9000
* Added a `NEWS.md` file to track changes to the package.
#' Access files in the current app
#'
#' NOTE: If you manually change your package name in the DESCRIPTION,
#' don't forget to change it here too, and in the config file.
#' For a safer name change mechanism, use the `golem::set_golem_name()` function.
#'
#' @param ... character vectors, specifying subdirectory and file(s)
#' within your package. The default, none, returns the root of the app.
#'
#' @noRd
app_sys <- function(...){
system.file(..., package = "polyqtlvis")
}
#' Read App Config
#'
#' @param value Value to retrieve from the config file.
#' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE.
#' If unset, "default".
#' @param use_parent Logical, scan the parent directory for config file.
#'
#' @noRd
get_golem_config <- function(
value,
config = Sys.getenv(
"GOLEM_CONFIG_ACTIVE",
Sys.getenv(
"R_CONFIG_ACTIVE",
"default"
)
),
use_parent = TRUE
){
config::get(
value = value,
config = config,
# Modify this if your config file is somewhere else:
file = app_sys("golem-config.yml"),
use_parent = use_parent
)
}
#' The application server-side
#'
#' @param input,output,session Internal parameters for {shiny}.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_server <- function( input, output, session ) {
# initialise reactive values object
rv <- reactiveValues()
# Input data ----
mod_import_panel_server("import_panel_ui_1", rv = rv)
# IBD estimation ----
mod_IBD_panel_server("IBD_panel_ui_1", rv = rv)
}
#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_ui <- function(request) {
tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# Your application UI logic
navbarPage(title = 'Polyploid QTL visualisation', inverse = TRUE,
# Input panel ----
tabPanel('Data import',
mod_import_panel_ui('import_panel_ui_1')
),
# IBD panel ----
tabPanel('IBD',
mod_IBD_panel_ui("IBD_panel_ui_1")
)
)
)
}
# External resources ----
#' Add external Resources to the Application
#'
#' This function is internally used to add external
#' resources inside the Shiny application.
#'
#' @import shiny
#' @importFrom golem add_resource_path activate_js favicon bundle_resources
#' @noRd
golem_add_external_resources <- function(){
add_resource_path(
'www', app_sys('app/www')
)
tags$head(
favicon(),
bundle_resources(
path = app_sys('app/www'),
app_title = 'polyqtlvis'
)
# Add here other external resources
# for example, you can add shinyalert::useShinyalert()
)
}
#' import
#'
#' @description A fct function
#'
#' @return The return value, if any, from executing the function.
#'
#' @noRd
#' IBD_panel UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
#' @importFrom polyqtlR estimate_IBD visualiseHaplo
mod_IBD_panel_ui <- function(id){
ns <- NS(id)
tagList(
sidebarLayout(
sidebarPanel(
h3('Estimation'),
# Method of estimation
selectInput(inputId = ns('ibd_method'),
label = 'Estimation Method',
choices = c('Heuristic'= 'heur',
'HMM' = 'hmm')),
# Mapping function
selectInput(inputId = ns('ibd_mf'),
label = 'Mapping Function',
choices = c('Haldane' = 'haldane',
'Kosambi' = 'kosambi')),
# Ploidy level
numericInput(inputId = ns('ibd_ploidy'),
label = 'Ploidy level',
min = 2,
value = 4,
step = 2),
# Cores
numericInput(inputId = ns('ibd_core'),
label = 'Numbers of processing cores',
min = 1,
value = detectCores() / 2,
max = detectCores() - 2),
# Estimate
actionButton(inputId = ns('go'),
label = 'Estimate')
),
mainPanel(
selectInput(inputId = ns('choice_lg'),
label = 'Select linkage group',
choices = 'Estimate or import first'),
selectInput(inputId = ns('choice_offspring'),
label = 'Select offspring',
choices = 'Estimate or import first'),
plotOutput(ns('plot_haplo'))
)
)
)
}
#' IBD_panel Server Functions
#'
#' @noRd
mod_IBD_panel_server <- function(id, rv){
moduleServer( id, function(input, output, session){
ns <- session$ns
# Side panel ----
observeEvent(input$go, {
rv$ibd_estimate <- estimate_IBD(phased_maplist = rv$linkmap,
genotypes = as.matrix(rv$snp),
method = input$ibd_method,
map_function = input$ibd_mf,
ploidy = input$ibd_ploidy,
ncores = input$ibd_core)
})
# Main panel ----
# Linkage group selection modifier
observeEvent(rv$ibd_estimate, {
updateSelectInput(session, 'choice_lg',
choices = 1:length(names(rv$ibd_estimate)))
})
# offspring selection modifier
observeEvent(input$choice_lg, {
req(rv$ibd_estimate)
updateSelectInput(session, 'choice_offspring',
choices = rv$ibd_estimate[[as.numeric(input$choice_lg)]]$offspring)
})
output$plot_haplo <- renderPlot({
req(rv$ibd_estimate)
visualiseHaplo(IBD_list = rv$ibd_estimate,
display_by = "name",
linkage_group = as.numeric(input$choice_lg),
select_offspring = input$choice_offspring,
multiplot = c(1, 1))
})
})
}
## To be copied in the UI
# mod_IBD_panel_ui("IBD_panel_ui_1")
## To be copied in the server
# mod_IBD_panel_server("IBD_panel_ui_1")
#' go UI Function
#'
#' @description A shiny Module for action buttons
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_go_ui <- function(id, label){
ns <- NS(id)
tagList(
actionButton(inputId = ns('go'),
label = label)
)
}
#' go Server Functions
#'
#' @noRd
mod_go_server <- function(id, rv, rvlab){
moduleServer( id, function(input, output, session){
ns <- session$ns
rv[[rvlab]] <- eventReactive(input$go, {input$go})
})
}
## To be copied in the UI
# mod_go_ui("go_ui_1")
## To be copied in the server
# mod_go_server("go_ui_1")
#' import UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_import_ui <- function(id, label, multiple = FALSE){
ns <- NS(id)
tagList(
fileInput(inputId = ns('file'),
label = label,
multiple = multiple)
)
}
#' import Server Functions
#'
#' @noRd
mod_import_server <- function(id, rv, rvlab){
moduleServer(id, function(input, output, session){
ns <- session$ns
# snp data is expected as matrix and needs other load in
observeEvent(input$file, {
req(input$file)
if(rvlab == 'snp'){
rv[[rvlab]] <- read.csv(input$file$datapath, row.names = 1)
} else {
name <- input$file$name[1] # if multiple csv length too long
extension <- tools::file_ext(name)
rv[[rvlab]] <- switch(extension,
csv = mapply(load_file,
name = input$file$name,
path = input$file$datapath,
SIMPLIFY = FALSE),
rds = load_file(name = name, path = input$file$datapath)
)
}
})
})
}
## To be copied in the UI
# mod_import_ui("import_ui_1")
## To be copied in the server
# mod_import_server("import_ui_1")
#' import_panel UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_import_panel_ui <- function(id){
ns <- NS(id)
tagList(
sidebarLayout(
sidebarPanel(
h3('Input'),
# Phenotype input
mod_import_ui(ns('phenotype'),
label = 'Phenotype'),
hr(),
# Link map input
mod_import_ui(ns('linkmap'),
label = 'Phase linkage map',
multiple = TRUE),
hr(),
# SNP dosage input
mod_import_ui(ns('snp'),
label = 'SNP Dosage matrix')
),
mainPanel(
tabsetPanel(
tabPanel('Phenotype',
mod_table_ui(ns('phenotype'))),
tabPanel('Linkage map',
selectInput(inputId = ns('choice_map'),
label = 'Select linkage group',
choices = 'Input map first'),
mod_table_ui(ns('linkmap'))),
tabPanel('SNP Dosage',
mod_table_ui(ns('snp')))
)
)
)
)
}
#' import_panel Server Functions
#'
#' @noRd
mod_import_panel_server <- function(id, rv){
moduleServer( id, function(input, output, session){
ns <- session$ns
# phenotype ----
mod_import_server('phenotype', rv = rv, rvlab = 'phenotype')
mod_table_server('phenotype', rv = rv, rvlab = 'phenotype')
# linkage map ----
mod_import_server('linkmap', rv = rv, rvlab = 'linkmap')
# selection modifier
observeEvent(rv$linkmap, {
file_list <- 1:length(rv$linkmap)
updateSelectInput(session, 'choice_map', choices = file_list)
})
rv$select_map <- eventReactive(input$choice_map, {input$choice_map})
mod_table_server('linkmap', rv = rv, rvlab = 'linkmap')
# # SNP dosage ----
mod_import_server('snp', rv = rv, rvlab = 'snp')
mod_table_server('snp', rv = rv, rvlab = 'snp')
})
}
## To be copied in the UI
# mod_import_panel_ui("import_panel_ui_1")
## To be copied in the server
# mod_import_panel_server("import_panel_ui_1")
# Load different filetypes based on file extension
# @param name string name of the file
# @param path string path of the file
# @return the loaded file
# @examples
# load_file('example.csv', './dir/example.csv')