我有一个关于闪亮的反应函数和一些伪代码的一般性问题,以基本上证明我正在尝试做什么 . 我基本上想知道为什么即使我的每个反应函数都非常快,但是当我运行闪亮的应用程序时,每个函数之间似乎存在显着的延迟 . 因此,似乎使应用程序变慢的不是我的个人功能,而是我的反应功能之间发生的任何事情 . 对于我想要做的一些评论,这是 pseudo code . 如果你需要一个完整的可重复的例子,我可能需要一段时间来创建一个,但我最终会完成它 . 至于现在,我试图解释我的思考过程,看看这是否是关于反应函数的一些更高级别的概念性事实,我应该看一下来解决我的速度问题 .

## 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. 
    }
)

现在每个反应函数(即filtered_data_frame(),输出$ plot1,输出$ table1 ...输出$ plot11,输出$ table11)都是非常快速的 . 我为每个函数的开头和每个函数的结束放了一个print语句,它们几乎是一个接一个地瞬间完成 . 例如:

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

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

     ## g is the name of the plot I return

     g
})

我为每个反应函数都有这些“开始”和“结束”的打印语句,每个单独的函数运行得非常快,但是一个函数的“结束”和另一个函数的“开始”之间有暂停,我无法解释 . 我不太确定导致这些长时间停顿的原因 . 我花了很多时间来优化我的每个函数只是为了发现大部分时间似乎都没有在函数内部,但可能会因为闪亮的反应特性而变慢 . 有没有办法减少闪亮的反应功能之间的长时间停顿?如果需要更多信息,我可以提供一个完整的可重复的示例,但同样可能需要一段时间才能使应用程序像我的一样长时间停顿 .

我注意到当我使用更大的数据集作为输入( initial_df 全局变量的更大数据集)时,我的应用确实运行得更慢,但在每个函数中并没有那么多,而是函数之间的长暂停 . 有没有人对此问题有任何见解?任何帮助是极大的赞赏!谢谢!