r语言 - 具有反应值的子集对象将失败


  1. 列表项

我有一个反应值不起作用的问题,因为我认为它应该有效。

下面的小代码描述了这个问题。函数firstsub2基本上会通过删除我们出于某种原因不想保留的样本(这是使用phyloseq biocondcutor包中的subset_samples函数(将对象子集化为较小的对象。

用户界面。R

myui <-     
fluidPage(

navbarPage("Project",

## foldchanges
tabPanel("Foldchanges",
titlePanel("Permanova: Analysis of variance using distance matrices"),

# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
actionButton("dofoldchanges", "Generate foldchanges")
),

mainPanel(
# Output: Tabset w/ plot, summary, and table ----
tabsetPanel(id="foldchanges",type = "tabs",
tabPanel(title="Summary", value=1, verbatimTextOutput("summary_foldchanges"))
#tabPanel("Table pairwise",value=4, dataTableOutput("tablepermanovapw"))

)
)
)
)
)
)

服务器。R

#To install phyloseq
#source("https://bioconductor.org/biocLite.R")
#biocLite("phyloseq")
library(shiny)
library(phyloseq)
myserver <- function(input, output, session) {
source("foldchanges.R", local = TRUE)
}

折叠变化。R

# Filter object
firstsub2 <- reactive({
values$rn <- as.character(sample_data(values$physeq)[,"Description"]$Description)))
cat(values$rn)
#The subset_samples function below will not work
filteredtaxo <- subset_samples(values$physeq, Description %in% values$rn)  
return(filteredtaxo)
})

values <- reactiveValues()
observeEvent(input$dofoldchanges, {
rich_sparse_biom = system.file("extdata", "rich_sparse_otu_table.biom", package = "phyloseq")
physeq = import_biom(rich_sparse_biom, parseFunction = parse_taxonomy_greengenes)
print(physeq)
values$physeq <- physeq
values$filtered <- firstsub2()

})

此示例基本上将返回导入的相同对象

您的代码仍然有一些错误,尤其是服务器文件(一些不必要的逗号(。

我认为您的应用程序可以正常工作,但它将始终是相同的文件,因为values$rn将始终相同。我在subset_sample下方添加了另一行(现在未注释(,以测试子集是否正常工作。例如,如果将values$rn更改为"human skin",您将看到不同的结果。

但是我不知道如何改变它。例如,当仅获取values$rn的第一个元素时,我得到一个未找到对象错误。但是当我像这样包括"人皮"时,它就起作用了。

但也许这已经对你有所帮助了。

library(shiny)
# source("https://bioconductor.org/biocLite.R")
# biocLite("phyloseq")
library(phyloseq)
myui <- {fluidPage(
navbarPage("Project",
## foldchanges
tabPanel("Foldchanges",
titlePanel("Permanova: Analysis of variance using distance matrices"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
actionButton("dofoldchanges", "Generate foldchanges")
),
mainPanel(
# Output: Tabset w/ plot, summary, and table ----
tabsetPanel(id="foldchanges",type = "tabs",
tabPanel(title="Summary", value=1, 
verbatimTextOutput("summary_foldchanges"),
verbatimTextOutput("summary_physeq"))
)))))
)}
myserver <- function(input, output, session) {
values <- reactiveValues()
firstsub2 <- reactive({
req(values$physeq)
input$dofoldchanges
values$rn <- as.character(sample_data(values$physeq)[,"Description"]$Description)
cat(values$rn)

#The subset_samples function below will not work
filteredtaxo <- subset_samples(values$physeq, "Description" %in% values$rn)
## Change it to one of the next lines, to see that subsetting works.
# filteredtaxo <- subset_samples(values$physeq, Description %in% "human skin")
# filteredtaxo <- subset_samples(values$physeq, Description %in% "human gut")
return(filteredtaxo)
})

observeEvent(input$dofoldchanges, {
rich_sparse_biom = system.file("extdata", "rich_sparse_otu_table.biom", package = "phyloseq")
physeq = import_biom(rich_sparse_biom, parseFunction = parse_taxonomy_greengenes)
print(physeq)
values$physeq <- physeq
values$filtered <- firstsub2()
})
output$summary_physeq <- renderPrint({
req(values$physeq)
values$physeq
})  
output$summary_foldchanges <- renderPrint({
req(values$filtered)
values$filtered
})
}
shinyApp(myui, myserver)

最新更新