Commit 6635a0a3 authored by Midoux Cedric's avatar Midoux Cedric

rework alpha with metashiny

parent f5b10abe
output$richnessAUI <- renderUI({ output$alphaPlotUI <- renderUI({
validate(need(data16S(), "")) validate(need(physeq(), ""))
box( box(
title = "Setting : " , title = "Setting : " ,
width = NULL, width = NULL,
...@@ -44,100 +44,65 @@ output$richnessAUI <- renderUI({ ...@@ -44,100 +44,65 @@ output$richnessAUI <- renderUI({
selectInput( selectInput(
"richnessX", "richnessX",
label = "X : ", label = "X : ",
choices = c("..." = 0, sample_variables(data16S())) choices = c("..." = "samples", sample_variables(physeq()))
), ),
selectInput( selectInput(
"richnessColor", "richnessColor",
label = "Color : ", label = "Color : ",
choices = c("..." = 0, sample_variables(data16S())) choices = c("..." = 0, sample_variables(physeq()))
), ),
selectInput( selectInput(
"richnessShape", "richnessShape",
label = "Shape : ", label = "Shape : ",
choices = c("..." = 0, sample_variables(data16S())) choices = c("..." = 0, sample_variables(physeq()))
), )
collapsedBox(verbatimTextOutput("richnessAScript"), title = "RCode")
) )
}) })
output$richnessAScript <- renderText({ output$alphaPlot <- metaRender2(renderPlot, {
if (!is.null(checkNull(input$richnessMeasures))) { validate(need(physeq(), "Requires an abundance dataset"))
measures <- data <- physeq()
glue("measures = c(\"{glue_collapse(input$richnessMeasures, sep='\", \"')}\")")
} else {
measures <- NULL
}
scriptArgs <- c("physeq = data", measures)
if (!is.null(checkNull(input$richnessX))) {
scriptArgs <- c(scriptArgs, glue("x = \"{input$richnessX}\""))
}
if (!is.null(checkNull(input$richnessColor))) {
scriptArgs <-
c(scriptArgs, glue("color = \"{input$richnessColor}\""))
}
if (!is.null(checkNull(input$richnessShape))) {
scriptArgs <-
c(scriptArgs, glue("shape = \"{input$richnessShape}\""))
}
if (!is.null(checkNull(input$richnessTitle))) {
scriptArgs <-
c(scriptArgs, glue("title = \"{input$richnessTitle}\""))
}
script <- c( alphaPlot_boxplot <- if (input$richnessBoxplot >= 2) {
scriptHead, metaExpr({geom_boxplot()})
"# Plot boxplot of alpha diversity",
glue(
"p <- plot_richness({glue_collapse(scriptArgs, sep=', ')})"
)
)
if (input$richnessBoxplot >= 2) {
script <- c(script,
"p <- p + geom_boxplot()")
} }
if (input$richnessBoxplot <= 2) {
script <- c(script, alphaPlot_point <- if (input$richnessBoxplot <= 2) {
"p <- p + geom_point()") metaExpr({geom_point()})
} }
script <- c(script, "", "plot(p)")
script <- c(script, "", "# Tables")
script <- c(
script,
glue(
"t <- estimate_richness({glue_collapse(c(\"data\", measures), sep=', ')})"
),
"write.table(t, file = \"richness.tsv\", sep = \"\\t\", col.names = NA)"
)
return(glue_collapse(script, sep = "\n")) metaExpr({
p <- plot_richness(
physeq = data,
x = ..(checkNull(input$richnessX)),
color = ..(checkNull(input$richnessColor)),
shape = ..(checkNull(input$richnessShape)),
title = ..(checkNull(input$richnessTitle)),
measures = ..(checkNull(input$richnessMeasures))
)
p + ..(alphaPlot_boxplot) + ..(alphaPlot_point)
})
}) })
output$richnessA <- renderPlot({ observeEvent(input$alphaPlot_output_code,
validate(need(data16S(), {
"Requires an abundance dataset")) displayCodeModal(
p <- plot_richness( expandChain(
physeq = data16S(), quote(library(phyloseq)),
x = ifelse(is.null(checkNull( quote(library(phyloseq.extended)),
input$richnessX "# Replace `data` with you own data.",
)), "samples", input$richnessX), output$alphaPlot()
color = checkNull(input$richnessColor), )
shape = checkNull(input$richnessShape), )
title = checkNull(input$richnessTitle), }
measures = checkNull(input$richnessMeasures) )
)
if (input$richnessBoxplot >= 2) {
p <- p + geom_boxplot()
}
if (input$richnessBoxplot <= 2) {
p <- p + geom_point()
}
return(p)
})
output$richnessATable <- renderUI({ output$alphaTable <- renderUI({
validate(need(data16S(), validate(need(physeq(), "Requires an abundance dataset"))
"Requires an abundance dataset")) box(
p(beautifulTable(data.frame( title = "Alpha diversity estimation",
SAMPLE = sample_names(data16S()), round(estimate_richness(data16S()), digits = 2) width = NULL,
))) status = "primary",
beautifulTable(tibble::rownames_to_column(round(estimate_richness(physeq()), digits = 2), var = "SAMPLE"))
)
}) })
richnessA <- fluidPage(box(width = NULL, tabsetPanel( alphaPlot <- fluidPage(outputCodeButton(withLoader(plotOutput("alphaPlot", height = 700))),
tabPanel("Plots", uiOutput("alphaPlotUI"))
withLoader(plotOutput( alphaTable <- fluidPage(uiOutput("alphaTable"))
"richnessA", height = 700
)),
uiOutput("richnessAUI")),
tabPanel("Tables", withLoader(uiOutput("richnessATable")))
)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment