侧边栏控件更新时延迟 tabPanel 内容更新

Delay in tabPanel content update when Sidebar control is updated

在下面的 Shiny 应用程序中,当 sidebarMenu 中的选择发生变化时,我正在更新 tabPanel 内容。但是,当我更改 sidebarMenu 中的选择时,tabPanel 内容更新会出现轻微延迟。

对于少量的输入值,这个延迟可以忽略不计,但是当我在sidebarMenu中有一个selectizeInput控件并且我在那里加载1000个值时,tabPanel中的内容更新是实质性的.有没有办法立即更新 tabPanel 内容?类似于 - 所有选项卡中的内容会在有人在 sidebarMenu 中做出选择后立即更新,甚至在有人单击选项卡之前?

library(shiny)
library(shinydashboard)

siderbar <- dashboardSidebar(
  sidebarMenu(
    # Add buttons to choose the way you want to select your data
    radioButtons("select_by", "Select by:",
                 c("Food Type" = "Food",
                   "Gym Type" = "Gym",
                   "TV show" = "TV"))
  )   
)

body <- dashboardBody(
  fluidRow(
    tabBox(
      side = "right",
      selected = "Tab3",
      tabPanel("Tab1", "Tab content 1", textOutput("tabset1Selected")),
      tabPanel("Tab2", "Tab content 2", textOutput("tabset2Selected")),
      tabPanel("Tab3", "Tab content 3", textOutput("tabset3Selected"))
    )
  ),
)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "tabBoxes"),
    siderbar,
    body
  ),
  server = function(input, output) {
    # The currently selected tab from the first box
    output$tabset1Selected <- output$tabset2Selected <- output$tabset3Selected <- renderText({
      input$select_by
    })
  }
)

如果输出不可见,使用 outputOptions 设置 suspendWhenHidden = FALSE 也会更新输出:

library(shiny)
library(shinydashboard)

siderbar <- dashboardSidebar(
  sidebarMenu(
    # Add buttons to choose the way you want to select your data
    selectizeInput(inputId = "select_by", label = "Select by:",
                   choices= as.character(1:1000))
  )   
)

body <- dashboardBody(
  fluidRow(
    tabBox(
      side = "right",
      selected = "Tab3",
      tabPanel("Tab1", "Tab content 1", textOutput("tabset1Selected")),
      tabPanel("Tab2", "Tab content 2", textOutput("tabset2Selected")),
      tabPanel("Tab3", "Tab content 3", textOutput("tabset3Selected"))
    )
  ),
)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(title = "tabBoxes"),
    siderbar,
    body
  ),
  server = function(input, output) {
    # The currently selected tab from the first box
    output$tabset1Selected <- output$tabset2Selected <- output$tabset3Selected <- renderText({
      input$select_by
    })
    
    lapply(list("tabset1Selected", "tabset2Selected", "tabset3Selected"), outputOptions, x = output, suspendWhenHidden = FALSE)
  }
)

此外,您应该考虑使用 server-side selectizeInput 来提高许多选择的性能。