Brilliant pauses between reactive functions

I have a general question about brilliant reactive features with some pseudocode to demonstrate, in essence, what I am trying to do. I am essentially wondering why, although each of my reactive features are very fast, but when I launch a brilliant application, there seems to be a significant delay between each of the features. So what seems to be slowing down the application is not my individual functions, but everything that happens between my reactive functions. This is pseudocodefor what I am trying to do with some comments. If you want a complete reproducible example, it may take a while to build, but I'll finish it eventually. At the moment I'm trying to just explain my thought process and see if this is a more conceptual, higher level idea about reactive functions that I should consider in order to solve my performance issue.

## Global variables: long_list, initial_df

shinyApp(ui = fluidPage(
              titlePanel("Example"),
              sideBarLayout(
                 sideBarPanel(

                    ## long_list is a variable that contains all of the possible choices. 
                    ## There are many choices.

                    selectInput("symbols",
                                "Possible Choices",
                                long_list)

                    ## Have a few conditional panels. These
                    ## contain date range sliders and tables. 

                    conditionalPanel(
                        tableOutput("table1")
                        tableOutput("table2")
                                .
                                .
                                .
                        tableOutput("table10")
                    ),
                    conditionalPanel(
                        tableOutput("table11")
                    )
                 ...),
                 mainPanel(

                    ## many plots being rendered

                    rCharts::showOutput("plot1", "nvd3"),
                    rCharts::showOutput("plot2", "nvd3"),
                            .
                            .
                            .
                    rCharts::showOutput("plot10", "nvd3"),
                    conditionalPanel(
                         ## some condition
                         rCharts::showOutput("plot11", "nvd3")
                    )
                ...)
              )
            ),
     server = function(input, output) {

              ## returns a data frame that reacts to a change in some input,
              ## such as a radio button or a slider, and then returns a 
              ## dataframe that my plotting functions will use. It filters
              ## a global data frame by a certain symbol in this pseudo example. 
              ## This makes the data frame of interest smaller and thus results 
              ## in different plots depending on which symbol the user chooses. 

              filtered_data_frame <- reactive({

                 ## df is a global variable that contains a pre-calculated data frame. 

                 if(!is.null(input$symbols)) {
                    return(dplyr::filter(df, symbol == input$symbols))
                 }

                 ## if the initial check does not pass (we have a null symbol)
                 ## then we return NULL. This is for validation in the 
                 ## plotting functions to do nothing if this function returns
                 ## NULL

                 return(NULL)
              })

              output$plot1 <- rCharts::renderChart2({

                  ## checks to make sure the function above returns a non-null 
                  ## result before proceeding. Otherwise does nothing (empty string "")

                  validate(
                      need(!is.null(filtered_data_frame()), "")
                  )

                  ## nvd3 plot using rCharts

                  g <- nPlot(...)
                  g
              })

              output$plot2 <- rCharts::renderChart2({
                  validate(
                      need(!is.null(filtered_data_frame()), "")
                  )
                  g <- nPlot(...)
                  g
              }) 

              ## This continues for say 11 plots, (i.e. output$plot3...output$plot11) 
              ## and similarly the for say 11 tables, (i.e output$table1...output$table11)
              ## The tables render data frames. 
    }
)

      

Now each of the reactive functions (i.e. filter_data_frame (), outputs $ plot1, outputs $ table1 ... output $ plot11, output $ table11) are all individually very fast. I put a print statement for the start of each function and the end of each function, and they are almost instantaneously one after the other. For example:

 output$plot1 <- rCharts::renderChart2({
     validate(...)

     print("start")
     ...
     g <- nPlot(...)
     ...
     print("end")

     ## g is the name of the plot I return

     g
})

      

I have these "start" and "end" print statements for each of my reactive functions, and each individual function is very fast, but there is a "pause" between one "end" function and a pause, and another "start" function that I cannot explain, I am not too sure what is causing these long pauses. I spent a lot of time optimizing each of my functions only to find out that most of the time it doesn't seem to be part of the functions, but maybe something slow with the reactive nature of the shiny ones. Is there a way to reduce the long pauses between reactive functions in the shiny state? If you need more information, I can provide a complete reproducible example, but again, it will probably take a while to make the application,which has as many pauses as mine.

I noticed that when I used a larger dataset as input (a larger dataset for the initial_df global variable ) my application ran slower, but again not so much inside each of the functions as rather long pauses between functions. Can anyone figure it out? Any help is greatly appreciated! Thank!

+3


source to share





All Articles