Skip to content
Prev 19067 / 21307 Next

[Bioc-devel] BiocParallel and Shiny

OK; I made BiocParallel a little easier to use (bpiterate() can now
take as its first argument a vector; it does not need to have an
'iterator' function). One needs to install the 'devel' version of the
package, currently

BiocManager::install("Bioconductor/BiocParallel")

Here's the complete example

library(shiny)
library(BiocParallel)

server <- function(input, output) {
    output$plot <- renderPlot({
        input$goPlot # Re-run when button is clicked

        withProgress(message = 'Making plot', value = 0, {
            ## Number of times we'll go through the loop
            n <- 100
            dat <- bpiterate(
                seq_len(n),
                function(i) {
                    Sys.sleep(.1)
                    data.frame(x = rnorm(1), y = rnorm(1))
                },
                REDUCE = function(x, y) {
                    incProgress(1/n)
                    rbind(x, y)
                },
                BPPARAM = SnowParam(tasks = n)
            )
        })

        plot(dat$x, dat$y)
    })
}

ui <- shinyUI(basicPage(
    plotOutput('plot', width = "300px", height = "300px"),
    actionButton('goPlot', 'Go plot')
))

shinyApp(ui = ui, server = server)

One thing about Henrik's suggestion is that it uses a number of
packages in addition to BiocParallel; if going that route maybe it
makes sense just to use those different packages rather than trying to
use them AND BiocParallel...

Martin
On Thu, Jul 7, 2022 at 8:32 AM Giulia Pais <giuliapais1 at gmail.com> wrote:
Message-ID: <CAFQL87MitoHM62xzeSq50umGd7HswSp56kij+kOPdMJ4KFWsNA@mail.gmail.com>
In-Reply-To: <DBAPR04MB7269E11A0F0CD1090E117FBBAA839@DBAPR04MB7269.eurprd04.prod.outlook.com>