1
votes

On a Shiny page I notice that on a given tabPanel, plots for all renderPlot() statements are displayed simultaneously rather than one after another. Even when I add Sys.sleep(n) in between these renderPlot ... it simply deplays the rendering, but the renderPlot() outputs are not displayed in the order of their execution. I would like them to display one after another and provide user progress bar to indicate which plot is being plotted. Thanks.

1
How about some sample code? - Mike Wise
Here it is, I am plotting two plots one after another ... they only appear at once, not as I expect one after another. I would want the progress bar to show the progress for the first one, then once the first is plotted the second progress bar shows and then second plot appears. For whatever reason it does not allow me to post more than certian character length so the code was added as Answer. - Ali

1 Answers

0
votes

UI

tabPanel 
        (
            sidebarLayout
            (
                sidebarPanel
                (
                    fileInput('dataSource', 'Upload Data',accept = c('text/csv','text/comma-separated-values','text/tab-separated-values','text/plain','.csv','.tsv'),multiple=TRUE)
                ),
                mainPanel
                (
                    fluidRow(column(width = 3, style = "background-color: transparent;", class = "well",plotOutput("comp1", height = 300,width = 300)),
                    column(width = 3, style = "background-color: transparent;", class = "well",plotOutput("comp2", height = 300,width = 300))),
                    tags$hr()
                )
            )
        )

Server

values <- reactiveValues(df_data = NULL)
    observeEvent(input$dataSource, { values$df_data <- read.csv(input$dataSource$datapath)})    

    Comp1 <- reactive({
    plComp1 <- eqComp1(values$df_data [-(1:2)]))))
    })
    Comp2 <- reactive({
    plComp2 <- eqComp2(values$df_data [-(1:2)]))))
    })

    output$comp1 <- renderPlot({
    withProgress(message = 'Plotting in progress ...', value = 0, {
       for (i in 1:15) {
         incProgress(1/15)
         Sys.sleep(0.5)
       }    
    plot( values@df_data[,1], Comp1())

    })
    })
    output$comp2 <- renderPlot({
    withProgress(message = 'Plotting in progress ...', value = 0, {
       for (i in 1:15) {
         incProgress(1/15)
         Sys.sleep(0.5)
       }    
    plot( values@df_data[,1], Comp2())

    })
    })