数值输入在Shiny中的响应速度太快

问题描述

我希望Shiny稍等一会儿,以便用户输入其组大小(不使用按钮)。这是我的代码的简单版本,但是在我的实际代码中,我有更多的用户输入(因此,我只希望Shiny仅等待2秒才能输入)。我一直在尝试找出如何将debounce用于此代码,但是我不确定。

library(shiny)

shinyApp(ui <- fluidPage(sidebarPanel(
  "",numericInput("groupSize",label =
                 "How many people will be with you?",value = ""),textoutput("output")
)),server <- function(input,output,session) {
  getNumber <- reactive({
    
  req(input$groupSize>=0)
  groupSize <- input$groupSize
  })
  
  output$output <- renderText({ 
    getNumber()
   })
})

解决方法

这与debounce一起使用:

  1. 创建反应式输入函数groupsize
  2. 将此函数传递给debounce以创建新函数groupsize_d
  3. 使用此新功能进行渲染
library(shiny)

shinyApp(ui <- fluidPage(sidebarPanel(
  "",numericInput("groupSize",label =
                 "How many people will be with you?",value = ""),textOutput("output")
)),server <- function(input,output,session) {
  groupsize <- reactive(input$groupSize)
  groupsize_d <- debounce(groupsize,2000)
  
  getNumber <- reactive({
    
    req(groupsize_d()>=0)
    groupsize_d()
  })
  
  output$output <- renderText({ 
    getNumber()
  })
})

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...