我有一个问题,反应值不起作用,因为我认为它应该工作。
下面的小代码描述了这个问题。函数firstsub2基本上会将一个对象子集为一个较小的对象,方法是删除出于某种原因我们不想保留的样本(这是使用phyloseq包中的subset_samples函数)。
UI.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"))
)
)
)
)
)
)SERVER.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)
}foldchanges.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()
})此示例将基本上返回导入的相同对象。
发布于 2018-06-29 12:48:28
您的代码仍然存在一些错误,特别是服务器文件(一些不必要的逗号)。
我认为你的应用程序可以正常工作,但它总是和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)https://stackoverflow.com/questions/51081241
复制相似问题