gpt4 book ai didi

r - 听 shiny 中的 reactive() 失效?

转载 作者:行者123 更新时间:2023-12-01 12:19:38 28 4
gpt4 key购买 nike

shiny 中是否有一个暴露的(甚至可能是非暴露的)函数会告诉我什么时候 react 失效?示例草稿:

ui.R

selectInput('select', ...)

服务器.R

myfunc <- reactive({ ... input$select ... })

output$listen <- textOutput({
valid_flag <- ???(myfunc)
paste('This function is', valid_flag)
})

如果 react 有效或无效,???() 函数会给我信息。

最佳答案

在浏览了 Shiny 的包代码后,我可能真的找到了解决方案。 reactive 类的对象是 S3 对象,但 react 机制“隐藏”在 R6 类 attr(object, "observable") 中。我上面的问题的解决方案是:

myfunc <- reactive({ ... input$select ... })

output$listen <- textOutput({
valid_flag <- attr(myfunc, "observable")$.invalidated
paste('This function is invalidated:', valid_flag)
})

这个例子可能不是最好的(我仍然不确定 attr(myfunc, "observable") 是否充当 react 对象,但我在不同的上下文中使用它 - 不是以 react 方式打印出来,而是通知代码的其他部分有关 react 堆栈的状态。

关于r - 听 shiny 中的 reactive() 失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45478521/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com