Hi,
I am fairly new to RShiny. I have installed the local RShiny Server on my Ubuntu desktop. I after reading the documentation, put my app file within a directory in the path "/srv/shiny-server". However, when i go to the "localhost:38/neuroapp" on the browser, i only see the file directory and not the app.
Below is my code for app.R:
`
library(reshape2)
library(shiny)
library(ggplot2)
library(gridExtra)
library(DT)
library(dplyr)
library(plyr)
library(gtools)
# Define UI for application that draws a histogram
main.dir <- "."
cmi.m <- as.data.frame(read.delim(paste(main.dir,"Clinical_Metabolite_Information.tab",
sep="/"),header=F,
as.is=T, sep="\t"),stringAsFactors=F)
csi.m <- as.data.frame(read.delim(paste(main.dir,"Clinical_Subject_Information.tab",
sep="/"),header=F,
as.is=T, sep="\t"),stringAsFactors=F)
Muts.t.melt.mean.normalized <- as.data.frame(read.delim(paste(main.dir,"Muts.t.melt.mean.normailized.tab",
sep="/"),header=T,
as.is=T, sep="\t"),stringAsFactors=F)
Muts.t.melt.mean.normalized <- Muts.t.melt.mean.normalized[-which(Muts.t.melt.mean.normalized$Type=="Depressed"),]
Muts.t.melt.mean.normalized <- Muts.t.melt.mean.normalized[-which(Muts.t.melt.mean.normalized$Type=="Dementia"),]
colnames(cmi.m) <- cmi.m[1,]
colnames(csi.m) <- csi.m[1,]
g<-"Age_years (mean \u00b1 SD)"
Encoding(g)<-"UTF-8"
colnames(csi.m)[9] <- g
cmi.m <- cmi.m[-1,]
csi.m <- csi.m[-1,]
csi.m[,9] <- gsub("±.*","",csi.m[,9])
csi.m[,9] <- gsub("\\(.*","",csi.m[,9])
csi.m <- apply(csi.m,2,function(x) gsub("±.*","",x))
csi.m <- apply(csi.m,2,function(x) gsub("œ\?.*","",x))
csi.m <- apply(csi.m,2,function(x) gsub("\\(.*","",x))
csi.m <- apply(csi.m,2,function(x) gsub("N/A",NA,x))
cmi.m <- apply(cmi.m,2,function(x) gsub("±.*","",x))
cmi.m <- apply(cmi.m,2,function(x) gsub("œ\?.*","",x))
cmi.m <- apply(cmi.m,2,function(x) gsub("\\(.*","",x))
cmi.m <- apply(cmi.m,2,function(x) gsub("\\[.*","",x))
cmi.m <- apply(cmi.m,2,function(x) gsub("^-$",NA,x))
cmi.m <- apply(cmi.m,2,function(x) gsub("NULL",NA,x))
cmi.m <- apply(cmi.m,2,function(x) gsub("N/A",NA,x))
cmi.m[!nzchar(cmi.m)] <- NA
cmi.m[,"corrected_type"] <- gsub("AD.*","AD",as.vector(cmi.m[,"corrected_type"]))
cmi.m[,"corrected_type"] <- gsub("MCI.*","MCI",as.vector(cmi.m[,"corrected_type"]))
cmi.m[,"corrected_type"] <- gsub("Control.*","Control",as.vector(cmi.m[,"corrected_type"]))
cmi.m[,"corrected_type"] <- gsub(".*AD","AD",as.vector(cmi.m[,"corrected_type"]))
cmi.m[,"corrected_type"] <- gsub(".*MCI","MCI",as.vector(cmi.m[,"corrected_type"]))
cmi.m[,"corrected_type"] <- gsub(".*Control","Control",as.vector(cmi.m[,"corrected_type"]))
#z <- "[Cho] (choline) (corrected for atrophy)"
#Muts <- Muts.t.melt.mean.normalized[Muts.t.melt.mean.normalized$metabolite==z,]
#Muts <- melt(Muts[,-4], id=c("PMID", "metabolite","Type"))
#Muts[,1] <- factor(as.numeric(as.character(Muts[,1])),levels = sort(unique(as.numeric(as.character(Muts[,1])))))
#p1 <- ggplot(Muts, aes(fill=Type, y=as.numeric(value), x=PMID)) +
# geom_bar(position="stack", stat="identity") +
# ggtitle(z) +
# theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(),
# axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
u <- fluidPage(
# Application title
titlePanel("ADNeuromine"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("x", "Select Age:",
min=20, max=100, value=50),
selectInput("z", "Metabolite:", sort(colnames(cmi.m)[-1:-5]))
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
tabPanel("Plot",
fluidRow(
plotOutput("distPlot4"))
),tabPanel("Summary", dataTableOutput("summary")))
)
)
)
s <- function(input, output) {
mydata <- reactive({
x <- input$x
z <- input$z
print(z)
subset.indx <- which(as.numeric(csi.m[,9])>=x)
subset.pmids <- unique(csi.m[subset.indx,2])
Muts1 <- as.data.frame(cmi.m[which(cmi.m[,2]%in%subset.pmids),])
#Muts2 <- as.data.frame(csi.m[subset.indx,])
Muts3 <- Muts.t.melt.mean.normalized[which(Muts.t.melt.mean.normalized$PMID%in%subset.pmids),]
Muts3 <- Muts3[which(Muts3$metabolite==z),]
Muts3.subset <- Muts3[which(!
is.na(Muts3$mean)),]
print(Muts3.subset)
Muts2 <- as.data.frame(csi.m[which(as.vector(csi.m[,2])%in%unique(Muts3.subset$PMID)),])
print(Muts2)
list(muts1=as.data.frame(Muts1),muts2=as.data.frame(Muts2),muts3=as.data.frame(Muts3))
})
output$distPlot4 <- renderPlot({
z <- input$z
Muts <- mydata()[[3]]
Muts[,1] <- factor(as.numeric(as.character(Muts[,1])),levels = sort(unique(as.numeric(as.character(Muts[,1])))))
hm <- sort(unique(Muts[,3]))
hm <- hm[-which(hm=="Control")]
hm <- c("AD","MCI","Control")
Muts[,3] <- factor(Muts[,3],levels = hm)
print(Muts)
p1 <- ggplot(Muts, aes(fill=Type, y=as.numeric(normalized_mean), x=PMID)) +
geom_bar(position="stack", stat="identity") +
ggtitle(paste(z," concentration across publications")) + xlab("PMID") +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
grid.arrange(p1, ncol=1,widths = c(2))
})
output$summary <- DT::renderDataTable({
Muts <- mydata()[[2]][,c(2,4,5,7:10)]
Muts
})
}
shinyApp(u,s)
`
Any help would be much appriciated.