I wrote a shiny script that was working fine. then I added a second plot and now I am getting the following error. cannot coerce type 'closure' to vector of type 'character' It worked with just divplotR, but when I added divplotS with fluidRow, I am getting the following error.
However, the fluidRow part looks fine, do they have to have two differnt input datasets ?
datasetNameDiv<-reactive({input$datasetDiv})
Any help appreciated, thanks
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
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)
})
}