Commit 0a0a0742 authored by Midoux Cedric's avatar Midoux Cedric

filter variable

parent de81072a
...@@ -166,12 +166,20 @@ observeEvent(input$okData, { ...@@ -166,12 +166,20 @@ observeEvent(input$okData, {
filterSample <- function() { filterSample <- function() {
modalDialog( modalDialog(
title = "Select some sample", title = "Select some sample",
size = "m",
checkboxGroupInput(inputId = "checkSamples", radioButtons(
label = "Sample to keep :", inputId = "filterCriteria",
choices = sample_names(physeq()), label = "Filter criteria : ",
#selected = sample_names(physeq()), inline = TRUE,
inline = TRUE), choices = c(
"Sample" = "sample",
sample_variables(physeq(), errorIfNULL = FALSE)
),
selected = "sample"
),
wellPanel(uiOutput("filterUI")),
footer = tagList(modalButton("Cancel"), footer = tagList(modalButton("Cancel"),
actionButton(inputId = "okData", label = "Refresh filter"), actionButton(inputId = "okData", label = "Refresh filter"),
actionButton(inputId = "selectData", label = "Select") actionButton(inputId = "selectData", label = "Select")
...@@ -179,16 +187,44 @@ filterSample <- function() { ...@@ -179,16 +187,44 @@ filterSample <- function() {
) )
} }
observeEvent(input$selectData, { output$filterUI <- renderUI({
if(is.null(input$checkSamples)) {showModal(dataInput(failed = TRUE))} if (is.null(input$filterCriteria))
try( return()
physeq(prune_samples(samples = input$checkSamples, physeq())), if (input$filterCriteria == "sample") {
silent = TRUE, label <- "Sample to keep :"
outFile = showModal(dataInput(failed = TRUE))) choices <- sample_names(physeq())
if (class(physeq()) == "phyloseq") {
removeModal()
} else { } else {
label <- "Variable to keep :"
choices <- levels(get_variable(physeq(), input$filterCriteria))
}
checkboxGroupInput(inputId = "filterCheck",
label = label,
choices = choices,
selected = choices,
inline = TRUE)
})
observeEvent(input$selectData, {
if (is.null(input$filterCheck))
{
showModal(dataInput(failed = TRUE)) showModal(dataInput(failed = TRUE))
} else {
try(
if (input$filterCriteria == "sample") {
physeq(prune_samples(samples = input$filterCheck, physeq()))
} else {
criteria <<- input$filterCriteria
check <<- input$filterCheck
physeq(subset_samples(physeq(), eval(parse(text = criteria)) %in% check))
},
silent = TRUE,
outFile = showModal(dataInput(failed = TRUE)))
if (class(physeq()) == "phyloseq") {
removeModal()
} else {
showModal(dataInput(failed = TRUE))
}
} }
}) })
......
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