Commit 17e2b430 authored by mahendra-mariadassou's avatar mahendra-mariadassou
Browse files

Update download button.

parent fb398661
#' @import shiny
#' @importFrom DT DT
#' @importFrom phyloseq tax_table
app_server <- function(input, output, session) {
# Load package data in the session (for testing purpose)
# data("physeq", package = "affiliationExplorer")
......@@ -11,26 +13,33 @@ app_server <- function(input, output, session) {
biomfile <- read_frogs_biom(input$biom$datapath)
# Read the tsv file --> readr
multihits <- read_multihits(input$tsv$datapath)
#
# Sanitize physeq, multi_hits and build dictionary for short OTU names
all <- sanitize_physeq_and_affi(biomfile, multihits)
physeq <- all$physeq
dict <- all$otu_dictionary
affi <- all$affi
# Ambiguous ASVs and their affiliation
ambiguous_otu <- unique(affi$OTU) ## this probably needs to be reactive
ambiguous_otu_affi <- phyloseq::tax_table(physeq)[ambiguous_otu, ] %>% as("matrix")
# Add ASV Select Input
insertUI(
selector = "#tmp",
where = "beforeEnd",
ui = selectInput("asv",
label = "Select ASV",
choices = all$otu_dictionary$OTU,
multiple = FALSE)
label = "Select ASV",
choices = ambiguous_otu,
multiple = FALSE)
)
observeEvent(input$asv, {
# Extract Affiliation for a given OTU
data <- extract_affiliation(all$affi, input$asv)
data <- extract_affiliation(affi, input$asv)
amb <- find_level(data)
output$txt <- renderUI({paste(input$asv, "- ", nrow(data) ," affiliation, ambiguity at rank ", amb)})
output$table <- DT::renderDT({data}, selection = 'single')
# If a column is selected, update affiliation
output$selection <- renderUI({
s = input$table_rows_selected
if (length(s)) {
......@@ -39,12 +48,23 @@ app_server <- function(input, output, session) {
})
})
## Reactive block to update ambiguous_otu, ambiguous_otu_affi and the list when clicking on the "Clean ASV" button
## cleaned_taxonomy <- as.character(data[s, ])
## phyloseq::tax_table(physeq)[input$asv, ] <- cleaned_taxonomy
## ambiguous_otu <- setdiff(ambiguous_otu, input$asv)
## updateUI
output$download <- downloadHandler(
filename = function() {
paste('data-', Sys.Date(), '.csv', sep='')
paste0('cleaned_biom-', Sys.Date(), '.biom')
},
content = function(con) {
write.csv(data, con)
phyloseq.extended::write_phyloseq(
physeq = physeq,
biom_file = con,
biom_format = "frogs"
)
## write.csv(data, con)
})
})
}
\ No newline at end of file
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