服务器繁忙时禁用输入

问题描述 投票:0回答:0

在服务器忙于计算时禁用所有输入的最佳方法是什么?

我有几个输入,它们的变化会触发小的计算和输出的渲染。通常一切正常,但如果有人更改滑块或数字输入太快,程序就会卡在数据准备/计算和绘图之间的某个地方。

  • 2023年处理此类问题的最佳方式是什么?请注意,这是一个与 here.

    中的问题非常相似的问题
  • 现在是否有任何解决方案适用于具有不同模块的整个应用程序,而无需使用

    shinyjs
    禁用/启用每个输入?此外,对于动态 UI,我不太喜欢使用操作按钮。

这里有一个例子,试着将 bins 从 10 增加到 20.

histogramInput <- function(id) {
  numericInput(NS(id, "bins"), "Select bins", 10, min = 1, step = 1)
}

histogramOutput <- function(id) {
  plotOutput(NS(id, "histogram"))
}

histogramServer <- function(id, value) {
  stopifnot(is.reactive(value))

  moduleServer(id, function(input, output, session) {

    # Some computational expensive data preparation
    dat_hist <- reactive({
      Sys.sleep(2)
      print(input$bins)
      list(dat = value(), bins = input$bins)
    })

    output$histogram <- renderPlot({
      req(dat_hist())

      graphics::hist(dat_hist()$dat, breaks = dat_hist()$bins)
    }, res = 96)
  })
}

histogramApp <- function() {
  ui <- fluidPage(
    histogramInput("test"),
    histogramOutput("test")
  )

  server <- function(input, output, session) {

    dat <- reactive({cars$speed})
    histogramServer("test", dat)
  }

  shinyApp(ui, server)
}
r shiny shinyjs
© www.soinside.com 2019 - 2024. All rights reserved.