r - 数字输入在 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
:
- 创建一个反应输入函数
groupsize
- 将此函数传递给以
debounce
创建一个新函数groupsize_d
- 使用这个新功能进行渲染
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()
})
})
推荐阅读
- codeigniter-4 - 哎呀!我们似乎遇到了障碍。请稍后再试
- for-loop - 为什么调用 .then 的语句会自动从 for 循环中排除
- react-native - 如何在 react-native-webview 中清除 cookie 和缓存数据
- react-admin - 当我单击行时如何更改列表的行背景
- flutter - 当 InkWell/GestureDetector 溢出父级时,如何使它们可点击?
- amazon-web-services - 在自定义 JSON 堆栈中传递敏感信息
- r - 折叠/组合多个相邻行,以 r 中的其他变量为条件
- java - 使用服务帐户方法使用 google Gmail API 时获取状态 400
- reactjs - 样式化组件插值函数中的“函数缺少返回类型”错误
- spring - 我应该在哪里为 Spring 的 @Qualifier 注释定义常量?