Hi everybody,
I'm trying to execute my code:
#! test
ui <- fluidPage(
"something",
titlePanel("something2"),
sidebarLayout(
sidebarPanel(
fileInput(inputId = "bedfile", label = NULL),
selectInput(inputId = "choosenFeature", label = "chose table", choices = c("exonAnnotations", "promsAnnotations", "intron.annotations"), selected = "casa"),
selectInput(inputId = "choosenValue", label = "chose table", choices = c("seqnames", "width", "rank", "SV", "frame", "distance.left", "distance.right"), selected = "width"),
width = 2
),
mainPanel(
tableOutput(outputId = "resultsTab"),
plotOutput(outputId = "resultsPlot"),
)
)
)
server <- function(input, output) {
source("~/Desktop/test.r")
resultsSV <- renderTable({
file = read.table(input$bedfile, sep='\t', header=T)
test(file)
})
output$resultsTab <- renderTable({
indTab <- match(input$choosenFeature, names(resultsSV))
resTab <- resultsSV[[indTab]]
return(resTab)
})
output$resultsPlot <- renderPlot({
indTab <- match(input$choosenFeature, names(resultsSV))
resTab <- resultsSV[[indTab]]
indPlot <- match(input$choosenValue, colnames(resTab))
resPlot <- resTab[, indPlot]
pie(resPlot)
})
}
shinyApp(server = server, ui = ui)
but unluckily it returns an error in the browser window: "object of type 'closure' is not subsettable"
in this case the "test" function I'm using, should return a list parsed from the input file or a toy list in case no input file is provided:
test = function(a){
if(missing(a)){
b <- list()
b[[1]] <- matrix(rep(c(123, 324234, 123123, 231), 5), ncol = 4)
colnames(b[[1]]) <- c("seqnames", "width", "rank", "SV")
b[[2]] <- matrix(rep(c(123, 324234, 123123, 231), 5), ncol = 4)
colnames(b[[2]]) <- c("seqnames", "width", "rank", "SV")
b[[3]] <- matrix(rep(c(123, 324234, 123123, 231), 5), ncol = 4)
colnames(b[[3]]) <- c("seqnames", "width", "rank", "SV")
names(b) <- c("exonAnnotations", "promsAnnotations", "intron.annotations")
} else {
b = list()
b[[1]] <- head(a)
b[[2]] <- head(a)
b[[3]] <- head(a)
names(b) <- c("exonAnnotations", "promsAnnotations", "intron.annotations")
}
return(b)
}
Anyway when I try to generate my table outside this script everything work fine, so I am wondering how to convert the input file into a table which the script can then use.
This is the script with the list generation before running the code (assuming you have already run the fluidpage part):
resultsSV <- test()
server <- function(input, output) {
source("~/Desktop/test.r")
# resultsSV <- renderTable({
# file = read.table(input$bedfile, sep='\t', header=T)
# test(file)
# })
output$resultsTab <- renderTable({
indTab <- match(input$choosenFeature, names(resultsSV))
resTab <- resultsSV[[indTab]]
return(resTab)
})
output$resultsPlot <- renderPlot({
indTab <- match(input$choosenFeature, names(resultsSV))
resTab <- resultsSV[[indTab]]
indPlot <- match(input$choosenValue, colnames(resTab))
resPlot <- resTab[, indPlot]
pie(resPlot)
})
}
shinyApp(server = server, ui = ui)
Where is the mistake ?!