From e606731d505c1e82a821df9f88ae01a5a223d76d Mon Sep 17 00:00:00 2001 From: agdamsbo Date: Fri, 8 Nov 2019 10:50:24 +0100 Subject: [PATCH] updates now with a shiny app --- .DS_Store | Bin 6148 -> 6148 bytes DESCRIPTION | 3 +- inst/hwe_calc/server.R | 92 ++++++++++++++++++++++++++++++++++++++ inst/hwe_calc/ui.R | 97 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 inst/hwe_calc/server.R create mode 100644 inst/hwe_calc/ui.R diff --git a/.DS_Store b/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..3da43d53b66209dee8f80c1200540132c3c9de4f 100644 GIT binary patch delta 222 zcmZoMXfc=|#>B`mF;Q%yo}wTt0|Nsi1A_oVPP$=ma(-^X#KhJ0AVC&}Oolv$Vuli! z1W*hH;BvY7E-pzq`AI+t4gpn-_gi-zbOf@IAjHF;Q%yo+1YW5HK<@2y9-+n8vnw1EUw?W_AvK4xj>{$am(+{342+ UKzW7)kiy9(Jj$D6L{=~Z03)*w`v3p{ diff --git a/DESCRIPTION b/DESCRIPTION index e6a7276..2399b07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: daDoctoR Type: Package Title: FUNCTIONS FOR HEALTH RESEARCH -Version: 0.1.0.9022 +Version: 0.1.0.9023 Author@R: c(person("Andreas", "Gammelgaard Damsbo", email = "agdamsbo@pm.me", role = c("cre", "aut"))) Maintainer: Andreas Gammelgaard Damsbo Description: I am a Danish medical doctor involved in neuropsychiatric research. @@ -12,6 +12,7 @@ Imports: broom, epiR, ggplot2, MASS +Suggest: shiny License: GPL (>= 2) Encoding: UTF-8 LazyData: true diff --git a/inst/hwe_calc/server.R b/inst/hwe_calc/server.R new file mode 100644 index 0000000..5ee7a82 --- /dev/null +++ b/inst/hwe_calc/server.R @@ -0,0 +1,92 @@ +#' +#' This is a Shiny web application. You can run the application by clicking +#' the 'Run App' button above. +#' +#' Find out more about building applications with Shiny here: +#' +#' http://shiny.rstudio.com/ +#' +#' +#' User requests: +#' +#' - Proper labelling of chart + +library(shiny) +library(ggplot2) +source("https://raw.githubusercontent.com/agdamsbo/daDoctoR/master/R/hwe_geno.R") + +# Define server logic required to draw a histogram + +server <- function(input, output, session) { + + cale <- reactive({ + as.numeric(input$ale) + }) + + dat<-reactive({ + df<-data.frame(lbls=c("MM","MN","NN","MO","NO","OO"), + value=rbind(input$mm,input$mn,input$nn,input$mo,input$no,input$oo), + stringsAsFactors = FALSE) + print(df) + df + }) + + cmm <- reactive({ + as.numeric(input$mm) + }) + + cmn <- reactive({ + as.numeric(input$mn) + }) + + cnn <- reactive({ + as.numeric(input$nn) + }) + + cmo <- reactive({ + as.numeric(input$mo) + }) + + cno <- reactive({ + as.numeric(input$no) + }) + + coo <- reactive({ + as.numeric(input$oo) + }) + + hwe_p <- function() ({ hwe_geno(cmm(),cmn(),cnn(),cmo(),cno(),coo(),alleles=cale()) }) + + output$allele.tbl <- renderTable({ hwe_p()$allele.dist }) + + output$obs.tbl <- renderTable({ hwe_p()$observed.dist }) + + output$exp.tbl <- renderTable({ hwe_p()$expected.dist }) + + output$chi.val <- renderTable({ hwe_p()$chi.value }) + + output$p.val <- renderTable({ hwe_p()$p.value }) + + output$allele.dist <- renderText({"Allele distribution"}) + + output$obs.dist <- renderText({"Observed distribution"}) + + output$exp.dist <- renderText({"Expected distribution"}) + + output$chi <- renderText({"Chi square value"}) + + output$p <- renderText({"P value"}) + + output$geno.pie.plt<- renderPlot({ + ggplot(dat(), aes(x="", y=value, fill=lbls))+ + geom_bar(width = 1, stat = "identity")+ + coord_polar("y", start=0)+ + scale_fill_brewer(palette="Dark2") + }) + + output$geno.pie.ttl <- renderText({"Genotype distribution"}) +} + +# Run the application +shinyApp(ui = ui, server = server) + diff --git a/inst/hwe_calc/ui.R b/inst/hwe_calc/ui.R new file mode 100644 index 0000000..0efacf9 --- /dev/null +++ b/inst/hwe_calc/ui.R @@ -0,0 +1,97 @@ +#' +#' This is a Shiny web application. You can run the application by clicking +#' the 'Run App' button above. +#' +#' Find out more about building applications with Shiny here: +#' +#' http://shiny.rstudio.com/ +#' +#' +#' User requests: +#' +#' - Proper labelling of chart + +library(shiny) +library(ggplot2) +source("https://raw.githubusercontent.com/agdamsbo/daDoctoR/master/R/hwe_geno.R") + +ui <- fluidPage( + + # Application title + titlePanel("Chi square test of HWE for bi- or triallelic systems"), + + sidebarLayout( + sidebarPanel( + + # Input: Numeric entry for number of alleles ---- + radioButtons(inputId = "ale", + label = "Number of alleles:", + inline = FALSE, + choiceNames=c("Two alleles (M, N)", + "Three alleles (M, N, O)"), + choiceValues=c(2,3)), + + h4("Observed genotype distribution"), + + numericInput(inputId = "mm", + label = "MM:", + value=NA), + + numericInput(inputId = "mn", + label = "MN:", + value=NA), + + numericInput(inputId = "nn", + label = "NN:", + value=NA), + conditionalPanel(condition = "input.ale==3", + + numericInput(inputId = "mo", + label = "MO:", + value=NA), + + numericInput(inputId = "no", + label = "NO:", + value=NA), + + numericInput(inputId = "oo", + label = "OO:", + value=NA)) + + ), + + mainPanel( + tabsetPanel( + tabPanel("Summary", + h3(textOutput("obs.dist", container = span)), + htmlOutput("obs.tbl", container = span), + + h3(textOutput("exp.dist", container = span)), + htmlOutput("exp.tbl", container = span), + + h3(textOutput("allele.dist", container = span)), + htmlOutput("allele.tbl", container = span), + + value=1), + + tabPanel("Calculations", + + h3(textOutput("chi", container = span)), + htmlOutput("chi.val", container = span), + + h3(textOutput("p", container = span)), + htmlOutput("p.val", container = span), + + value=2), + + + + tabPanel("Plots", + h3(textOutput("geno.pie.ttl", container = span)), + plotOutput("geno.pie.plt"), + + value=3), + selected= 2, type = "tabs") + ) + ) +)