Shiny R选项卡设置同步处理

Shiny R选项卡设置同步处理,shiny,tabpanel,Shiny,Tabpanel,在我的R Shining应用程序中,我的tabsetPanel中有许多选项卡面板 在我单击某个选项卡之前,特定选项卡的图表不会开始加载 因此,浏览所有选项卡的内容需要很长时间 有没有办法让所有标签在应用程序启动时先处理,这样当我转到不同的标签时,所有图表都已经存在 我创建了一个带有两个直方图的简单示例: server <- function(input, output) { output$distPlot <- renderPlot({ hist(rnorm(1000

在我的R Shining应用程序中,我的tabsetPanel中有许多选项卡面板

在我单击某个选项卡之前,特定选项卡的图表不会开始加载

因此,浏览所有选项卡的内容需要很长时间

有没有办法让所有标签在应用程序启动时先处理,这样当我转到不同的标签时,所有图表都已经存在

我创建了一个带有两个直方图的简单示例:

  server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(100000000), col = 'darkgray', border = 'white')
  })


  output$distPlot2 <- renderPlot({
    hist(rnorm(100000000), col = 'red', border = 'white')
  })
  outputOptions(output,"distPlot2",suspendWhenHidden = FALSE)

}

ui <- fluidPage(

  tabsetPanel(
    tabPanel("1",plotOutput("distPlot")
      ),
    tabPanel("2",plotOutput("distPlot2")
      )
    )

)

shinyApp(ui = ui, server = server)

server您可以使用
suspendWhenHidden
参数来控制渲染行为:

当隐藏时暂停。当“TRUE”(默认值)时,输出 对象在上隐藏时将被挂起(不执行) 这个网页。当“FALSE”时,输出对象将不会 隐藏时挂起,如果已隐藏,则挂起 暂停,然后将立即恢复


如果这还不够,您可以在应用程序启动时(在服务器功能外部)或按用户(在服务器渲染块外部)执行代码中昂贵的部分。

您好,您可以看看我的可复制示例代码吗。我对加载进行了计时,发现该选项没有按预期工作。嗯,很有趣。我稍后会看一看,如果我知道这里发生了什么,会告诉你的。