gpt4 book ai didi

shiny - 如何使用代码使响应式(Reactive)观察者无效?

转载 作者:行者123 更新时间:2023-12-04 18:40:52 27 4
gpt4 key购买 nike

给定类似伪代码的代码:

dateRange <- reactive({
input$select_dates #action button

save_selected_date_range()
isolate(input$dateRange)
})


customerId <- reactive({
#check if customer has saved date range if so trigger
saved_info <- saved_preferences(input$customerId)
if(nrow(saved_info) > 0) {
flog.info(saved_info)
updateDateRangeInput(session, "dateRange", start = saved_info$start, end = saved_info$start)
}

input$customerId
})

场景:

输入:
选定的日期范围和客户选择器。当按下操作按钮时,日期范围被注册。

所需操作:
我们希望能够在选择客户时加载已保存的日期范围(如果可用)。

问题:
如何触发 input$select_dates 就像按下操作按钮一样?类似 invalidateLater没有计时器就好了。或者,如果有手动方式将 input$select_dates 标记或标记为无效。

最佳答案

定义 react 值
rv <- reactiveValues( v = 0)
把它放在你的响应式(Reactive)表达中

dateRange <- reactive({
rv$v
input$select_dates #action button

save_selected_date_range()
isolate(input$dateRange)
})

只需更改 rv$v 的值(如 rv$v <- rv$v + 1 )在您代码的任何部分和 dateRage表达式将失效。

关于shiny - 如何使用代码使响应式(Reactive)观察者无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33382525/

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