r - 如何在闪亮的反应值中使用去抖动
问题描述
我知道我可以像这样将 debounce 与 reactive() 一起使用,这是我需要的那种行为,但我想改用 reactiveValues()。
ui <- fluidPage(
textInput(inputId = "text",
label = "To see how quickly..."),
textOutput(outputId = "text")
)
server <- function(input, output, session) {
text_input <- reactive({
input$text
})
debounce(text_input, 2000)
output$text <- renderText({
text_input()
})
}
shinyApp(ui, server)
}
但我更喜欢使用 reactiveValues() 而不是 reactive()。有什么方法可以通过 reactiveValues() 使用 debounce?这不起作用:
ui <- fluidPage(
textInput(inputId = "text",
label = "To see how quickly..."),
textOutput(outputId = "text")
)
server <- function(input, output, session) {
values <- reactiveValues()
observe({
values$text= function(x)input$text
values$t <-
debounce(values$text(),2000)
})
output$text <- renderText({
values$t()
})
}
shinyApp(ui, server)
我得到一个错误Warning: Error in r: could not find function "r"
,我猜是因为values
不是反应式表达?
解决方案
尝试这个。我删除了()
aftervalues$text
因为你想要函数/表达式,而不是解析的值:
library(shiny)
ui <- fluidPage(
textInput(inputId = "text",
label = "To see how quickly..."),
textOutput(outputId = "text")
)
server <- function(input, output, session) {
values <- reactiveValues()
observe({
values$text <- function(x) {input$text}
values$t <- debounce(values$text, 2000)
})
output$text <- renderText({
values$t()
})
}
shinyApp(ui, server)
推荐阅读
- spring - @Async 或 JMS 队列
- r - 带有可选变量的函数内部的 dplyr filter() (filter_if 也许?)
- sql - 在 Dremio 查询中使用 FLATTEN 时,有没有办法包含元素索引?
- wordpress - 使用 587 设置 Wordpress Post SMTP 和 Office 365 端口时出现延迟是否正常?
- python - 我尝试使用 openCV python 将网络摄像头视频录制到文件中,我无法用我的任何视频播放器打开文件这是我的代码
- laravel - 在关系多个模式上使用 eloquent 的问题
- android - 如何创建将 LocalDate 转换为 Room 可以理解/保存的格式的 TypeConverter?
- saml - SAMLResponse 是否应该包含额外的换行符?
- css - 如何防止多行文本填充父元素的整个宽度
- ios - Swift/iOS TravisCI 管道卡住克隆 cocoapods