R 具有被动值的子集对象将失败 列表项

R 具有被动值的子集对象将失败 列表项,r,shiny,R,Shiny,我有一个问题,反应值没有发挥作用,因为我认为它应该发挥作用 下面的小代码描述了这个问题。函数firstsub2基本上将通过移除我们出于某种原因不想保留的样本(这是使用phyloseq biocondcutor包中的subset_samples函数)将对象子集为较小的对象 用户界面 myui您的代码仍然有一些错误,尤其是服务器文件(一些不必要的逗号) 我认为你的应用程序可以正常工作,但它将始终是相同的文件,因为值$rn将始终是相同的。我在您的subset\u示例下面添加了另一行(现在未注释),以测

我有一个问题,反应值没有发挥作用,因为我认为它应该发挥作用

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

用户界面


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

我认为你的应用程序可以正常工作,但它将始终是相同的文件,因为
值$rn
将始终是相同的。我在您的
subset\u示例
下面添加了另一行(现在未注释),以测试子集是否工作。例如,如果将
值$rn
更改为
“人类皮肤”
,您将看到不同的结果

但我不知道如何改变它。以
值$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://bioconductor.org/biocLite.R")
#生物晶石(“phyloseq”)
图书馆(phyloseq)

myui您的代码/错误不可复制。1) 它不是一个完整的闪亮应用程序,2)输入数据丢失。@SeGa您好,我添加了一个完全可复制的示例。我认为问题来自软件包的subset_samples函数
#'#subset_samples(GlobalPatterns,SampleType==“Ocean”)subset_samples
#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)
}
# 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()


})
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)