RSHINY制作了包含“ ==”的子集语句,输入值,“对象输入$ ...未找到”

时间:2018-11-05 16:56:39

标签: r shiny shiny-server shiny-reactivity

对于Phyloseq子设置功能,subset_taxa()我希望使其具有Phylum == input$phy。 (其中input$physelectInput中的Shiny输入)。看来我可以将selectInput语句用于只有一个等号的参数,但是有办法吗?

这是我的代码。

这里只是一些全局变量

library(devtools)
library(phyloseq)
library(ggplot2)


plot_bar_2 <-  function (physeq, x = "Sample", y = "Abundance", fill = NULL, 
title = NULL, facet_grid = NULL, border_color = NA) 
{
  mdf = psmelt(physeq)
  p = ggplot(mdf, aes_string(x = x, y = y, fill = fill))
  p = p + geom_bar(stat = "identity", position = "stack",  color = 
border_color)
  p = p + theme(axis.text.x = element_text(angle = -90, hjust = 0))
  if (!is.null(facet_grid)) {
    p <- p + facet_grid(facet_grid)
  }
  if (!is.null(title)) {
    p <- p + ggtitle(title)
  }
  return(p)
}


  Group.Names <- GlobalPatterns@sam_data@names

  Group.Names <- c("Sample", Group.Names)

  taxa <- c("Phylum", "Class", "Order", "Family", "Genus", "Species")

  Custom <- c("#556270", "#4ECDC4", "#C7F464", "#FF6B6B", "#008DD5", 
  "#379F7A", "#78AE62", "#BBB749", "#E0FBAC", "#C8E011", "#174546", 
  "#FF3700", "#FF0072")
  cp <- c("Accent", "Dark2", "Paired", "Pastel1", "Pastel2", "Set1", "Set2", 
  "Set3")

  Phylum.table <- 
  c('Crenarchaeota','Euryarchaeota','Actinobacteria','Spirochaetes','MVP- 15','Proteobacteria','SBR1093','Fusobacteria','Tenericutes','ZB3','Cyanobacteria','GOUTA4','TG3','Chlorobi','Bacteroidetes','Caldithrix','KSB1','SAR406','LCP-89','Thermi','Gemmatimonadetes','Fibrobacteres','GN06','AC1','TM6','OP8','Elusimicrobia','NC10','SPAM','Acidobacteria','CCM11b','Nitrospirae','NKB19','BRC1','Hyd24-12','WS3','PAUC34f','GN04','GN12','Verrucomicrobia','Lentisphaerae','LD1','Chlamydiae','OP3','Planctomycetes','Firmicutes','OP9','WPS-2','Armatimonadetes','SC3','TM7','GN02','SM2F11','ABY1_OD1','ZB2','OP11','Chloroflexi','SC4','WS1','GAL15','AD3','WS2','Caldiserica','Thermotogae','Synergistetes','SR1')

  data(GlobalPatterns)

我的ui.r文件

library(shiny)

shinyUI(fluidPage(

  titlePanel("Microbiome Bar Plots"),

  sidebarLayout(
    sidebarPanel(
       selectInput("data",
                   "Method of Measurement: ",
                   c("Abundance", "Relative Abundance")),
       selectInput("independent",
                   "Select Grouping Method: ",
                     Group.Names),
       selectInput("Phylum",
                   "Choose Phylum Subset: ",
                    Phylum.table),
       sliderInput("subset",
                   "Select OTU Number: ",
                   min = 0, max = 5000, value = 50),
       selectInput("taxanomy",
                   "Select Taxa fill",
                   taxa),
       selectInput("color",
                   "Select Color Palette",
                   cp),
       selectInput("Background",
                   "Select Graph Background",
                   c("Black & White", "Minimal", "Grey", "Light", "Dark", 
"Classic"))

    ),

    # Show a plot of the generated distribution
    mainPanel(
       plotlyOutput("myPlot")
    )
  )
))

我的server.r文件

  library(shiny)

shinyServer(function(input, output) {

  output$myPlot <- renderPlot({

ok      <- input$color
in.data <- input$data 
in.ind  <- input$independent
in.phy <-  input$Phylum
in.tax  <- input$taxanomy
in.bg   <- input$Background
in.name <- input$name


if(in.bg == "Black & White"){
  theme_set(theme_bw())
}
else if(in.bg == "Minimal"){
  theme_set(theme_minimal())
}
else if(in.bg == "Grey"){
  theme_set(theme_grey())
}
else if(in.bg == "Light"){
  theme_set(theme_light())
}
else if(in.bg == "Dark"){
  theme_set(theme_dark)
}
else if(in.bg == "Classic"){
  theme_set(theme_classic())
}


  if (in.data == "Abundance") {

  gp.ch <- subset_taxa(physeq = GlobalPatterns, Phylum == Phylum.table[1])
  gp <- prune_samples(sample_sums(gp.ch)>=(input$subset), gp.ch)
  p <- plot_bar_2(gp, x = in.ind, fill = in.tax) 
  p + geom_bar(stat = "identity") + scale_fill_brewer(palette = ok, na.value = "light grey")
  }
  })
  })

所以说subset_taxa(physeq = GlobalPatterns, Phylum == Phylum.table[1])的地方 我想说Phylum == in.phy。也就是说,无论我在“闪亮”应用中单击的任何Phylum,它将替换Phylum.table[1](也称为“ Crenarchaeota”)或Phylum.table[2](即“ Euryarchaeota”)。当我将其设置为in.phy时,它说

  找不到

对象'in.phy'。

0 个答案:

没有答案