本文介绍了如何在闪亮的reactiveValues中使用去抖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以像这样使用reactive()去抖动,这是我需要的那种行为,但我想改用reactiveValues().

I understand that I can use debounce with reactive() like this, and this is the sort of behaviour I need, but I want to use reactiveValues() instead.

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().有什么方法可以将 debounce 与reactiveValues() 一起使用?这不起作用:

But I would prefer to use reactiveValues() rather than reactive().Is there any way to use debounce with reactiveValues()?This does not work:

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: E​​rror in r: could not find function "r",我猜是因为 values 不是反应式表达式?

I get an error Warning: Error in r: could not find function "r", I guess because values is not a reactive expression?

推荐答案

试试这个.我在 values$text 之后删除了 () 因为你想要函数/表达式,而不是解析的值:

Try this. I removed the () after values$text because you want the function/expression, not the resolved values:

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)

这篇关于如何在闪亮的reactiveValues中使用去抖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 12:49