use shiny with uploaded data

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 ?!

This is almost always from referencing a reactive without using ()

Also, don't assign a render* function to a bare name, only to an output$name..

Thanks for answering.
the errors were:
to read a table from input file I had to use "input$bedfile$datapath" instead of "input$bedfile" and the one mentioned by you.

Why you suggest to dont use a bare name even if it is an internal variable ?

do you want to render to an output, or create a reactive data object ?
its generally going to simply be redundant if its a renderobject as its not good for much more than assigning to an ouptut$

I see

Thanks for helping

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.