r语言 - 闪亮 - 不能将类型"闭包"强制为类型"字符"的向量



我写了一个效果很好的闪亮脚本。然后,我添加了第二个图,现在我收到以下错误。无法将类型'闭合'限制为类型'cartare'的向量'它仅与DivPlotr一起使用,但是当我添加Fluidrow的Divplots时,我会遇到以下错误。

但是,流体部分看起来不错,它们必须具有两个不同的输入数据集吗?

datasetNamediv< - reactive({input $ datasetDiv}(

任何帮助,感谢,谢谢

ui

    ui <- fluidPage(
  # Make a title to display in the app
  titlePanel(" Exploring the Effect of Metarhizium on the Soil and Root Microbiome "),
  # Make the Sidebar layout
  sidebarLayout(
    # Put in the sidebar all the input functions
    sidebarPanel(
      tabsetPanel(id="tabs",
                  tabPanel("diversity",br(), 
                           p("On this tab you can visulize differnces in diversity measures n
                             first choose your dataset (either bacterial or fungal, and the phylogenetic resolution),then the specific otu"),
                           selectInput('datasetDiv', 'dataset', names(abundance_tables),selected=names(abundance_tables)[1]),
                           selectInput('index','index of interest',Indices,selected="Diversity_sh"))
      ) 
    ),
    # Put in the main panel of the layout the output functions 
    mainPanel(
      conditionalPanel(condition="input.tabs == 'diversity'",
                       h2("plots for different diversity indices"),
                       h3("Root"),
                       #plotOutput('divplotR')
                       fluidRow(
                        column(strong,"Root",width=6,plotOutput('divplotR')),
                        column(strong,"Rhizospheric Soil",width=6,plotOutput('divplotS'))
                        )
      )
    )
  )
)
#### 

服务器

server <- function(input, output){
  # Return the requested dataset ----
  datasetNameDiv<-reactive({input$datasetDiv})
  ## diversity plots
  output$divplotR<-renderPlot({
    req(is.null(input$otu)==F)
    df<-abundance_tables[[datasetNameDiv()]]
    index<-indexInput()
      ## Root first
      df_loc<-getSRSub(df,"R")
      df_locB<-getBeanSub(df_loc)
      #  df_name<-"fungi_family_soil"
      evenS<-function(df){apply(df,1,function(col) diversity(col)/log(specnumber(col)))}
      dat.indices<-data.frame(Diversity_sh=apply(df_locB,1,function(x) diversity(x, index = "shannon")),
                              Diversity_si=apply(df_locB,1,function(x) diversity(x, index = "simpson")),
                              Evenness=apply(df_locB,1,function(x) diversity(x)/log(specnumber(x))),
                              Richness_chao1=apply(df_locB,1,function(x) estimateR(round(x), index="chao"))[2,]
      )
      df_annot<-merge(dat.indices,sample_metadata,by="row.names")                             
      df_annot<-droplevels(df_annot)
      ## plot
      ## melt and add sample metadata
      #
      # renaming Fungi level to metarhizium
      levels(df_annot$Fungi)<-c("M+","M-")
      levels(df_annot$Location)<-c("Root","Rhizospheric Soil")
      #methods t.test wilcox.test kruskal.test anova
      ggplot(df_annot,aes_string(x="Fungi",y=index,Fill="Fungi"))+
        geom_boxplot(alpha=0.8)+facet_wrap(~Insect,scales="free")+
        geom_point(aes(fill=Fungi),size = 3, shape = 21)+
        stat_compare_means(label="p.format",method="wilcox.test")+
        guides(fill=guide_legend("M. robertsii")) +
        #ggtitle(df_name)+
        ylab(paste(index))+
        xlab("M. robertsii")+
        #    scale_x_discrete(labels= c("M+","M-","soil alone"))+
        theme(plot.title = element_text(size = 18, face = "bold"))+
        theme(axis.text=element_text(size=14),
              axis.title=element_text(size=14)) + 
        theme(legend.text=element_text(size=14),
              legend.title=element_text(size=14)) +
        theme(strip.text.x = element_text(size = 14))
  })
  #
  output$divplotS<-renderPlot({
    req(is.null(input$otu)==F)
    df<-abundance_tables[[datasetNameDiv()]]
    index<-indexInput()
    ## Root first
    df_loc<-getSRSub(df,"S")
    #df_locB<-getBeanSub(df_loc)
    #  df_name<-"fungi_family_soil"
    evenS<-function(df){apply(df,1,function(col) diversity(col)/log(specnumber(col)))}
    dat.indices<-data.frame(Diversity_sh=apply(df_loc,1,function(x) diversity(x, index = "shannon")),
                            Diversity_si=apply(df_loc,1,function(x) diversity(x, index = "simpson")),
                            Evenness=apply(df_loc,1,function(x) diversity(x)/log(specnumber(x))),
                            Richness_chao1=apply(df_loc,1,function(x) estimateR(round(x), index="chao"))[2,]
    )
    df_annot<-merge(dat.indices,sample_metadata,by="row.names")
    # for the insect subset (no "bulk soil")
    df_annotI<-subset(df_annot,Insect=="Insect")                         
    # renaming Fungi level to metarhizium
    levels(df_annotI$Fungi)<-c("M+","M-")
    levels(df_annotI$Location)<-c("Root","Rhizospheric Soil")
    df_annotI<-droplevels(df_annotI)
    #methods t.test wilcox.test kruskal.test anova
    plotinsect<-ggplot(df_annotI,aes_string(x="Fungi",y=index,Fill="Fungi"))+
      geom_boxplot(alpha=0.8)+
      geom_point(aes(fill=Fungi),size = 3, shape = 21)+
      stat_compare_means(label="p.format",method="wilcox.test")+
      guides(fill=guide_legend("M. robertsii")) +
      ggtitle("Insect")+
      ylab(paste(index))+
      xlab("M. robertsii")+
      #scale_x_discrete(labels= c("M+","M-","soil alone"))+
      theme(plot.title = element_text(size = 18, face = "bold"))+
      theme(axis.text=element_text(size=14),
            axis.title=element_text(size=14)) + 
      theme(legend.text=element_text(size=14),
            legend.title=element_text(size=14)) +
      theme(strip.text.x = element_text(size = 14))
    ####
    # for the No- insect subset (no "bulk soil")
    df_annotNI<-subset(df_annot,Insect=="NI")                             
    # renaming Fungi level to metarhizium
    df_annotNI$Fungi<-as.character(df_annotNI$Fungi)
    df_annotNI$Fungi[which(df_annotNI$Bean =="No bean")]<-"bulk_soil"
    df_annotNI$Fungi<-as.factor(df_annotNI$Fungi)
    #revalue(df_annotNI$Fungi, c("Fungi"="M+", "NF"="M-","bulk_soil=bulk_soil"))
    levels(df_annotNI$Fungi)<-c("bulk_soil","M+","M-")
    levels(df_annotNI$Location)<-c("Root","Rhizospheric Soil")
    #df_annotNI<-droplevels(df_annotNI)
    #methods t.test wilcox.test kruskal.test anova
    my_comparisons <- list( c("M+", "M-"), c("M+", "bulk_soil"), c("M-", "bulk_soil") )
    plotNinsect<-ggplot(df_annotNI,aes_string(x="Fungi",y=index,Fill="Fungi"))+
      geom_boxplot(alpha=0.8)+
      geom_point(aes(fill=Fungi),size = 3, shape = 21)+
      stat_compare_means(comparisons=my_comparisons)+
      #stat_compare_means(label="p.format",method="wilcox.test")+
      guides(fill=guide_legend("M. robertsii")) +
      ggtitle("No_insect")+
      ylab(paste(index))+
      xlab("M. robertsii")+
      scale_x_discrete(labels= c("M+","M-","soil alone"))+
      theme(plot.title = element_text(size = 18, face = "bold"))+
      theme(axis.text=element_text(size=14),
            axis.title=element_text(size=14)) + 
      theme(legend.text=element_text(size=14),
            legend.title=element_text(size=14)) +
      theme(strip.text.x = element_text(size = 14))
    grid.arrange(plotinsect, plotNinsect, ncol=2)
  })
}

oopps我发现了问题

                   fluidRow(
                    column(**strong,"Root"**,width=6,plotOutput('divplotR')),
                    column(**strong,"Rhizospheric Soil",**width=6,plotOutput('divplotS'))
                    )

应该是

                   fluidRow(
                    column(**strong("Root")**,width=6,plotOutput('divplotR')),
                    column(**strong("Rhizospheric Soil")**,width=6,plotOutput('divplotS'))
                    )

最新更新