首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用反应性值替换对象将失败

使用反应性值替换对象将失败
EN

Stack Overflow用户
提问于 2018-06-28 11:01:59
回答 1查看 81关注 0票数 0
  1. 列表项目

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

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

UI.R

代码语言:javascript
复制
 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

代码语言:javascript
复制
#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

代码语言:javascript
复制
# 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()


})

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

EN

回答 1

Stack Overflow用户

发布于 2018-06-29 12:48:28

您的代码仍然存在一些错误,特别是服务器文件(一些不必要的逗号)。

我认为你的应用程序可以正常工作,但它总是和values$rn一样的文件。我在您的subset_sample下面添加了另一行(现在未注释),以测试该子设置是否有效。例如,如果将values$rn更改为"human skin",则会看到不同的结果。

但我不知道怎么改变它。例如,当只接受values$rn的第一个元素时,我得到一个对象未找到错误。但是当我把“人类皮肤”包括在内的时候,它就起作用了。

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

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51081241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档