[英]Is there a way to use nested reactivePoll inside a reactive/observe to render a plot dependent on changes in DB and on UI both
[英]Use ReactivePoll inside an observe (R Shiny)
我試圖在一個observe
有一個reactivePoll
,因為我需要它才能在我的應用程序中的一些req
fullfil之后啟動(否則它可能會崩潰),然后將它傳遞給我正在使用的會話變量reactiveValues
。 出於某種原因,每次我執行的變量的變化,它看起來像reactivePoll
產生自身的拷貝,並開始執行checkFunc超過需要。 最小的例子:
library(shiny)
ui <- fluidPage(selectInput("x", "Change options", c(1, 2)))
server <- function(input, output, session) {
v <- reactiveValues()
observe({
print("obs")
req(input$x)
v$a <- reactivePoll(5000, session,
checkFunc = function() {
print("test")
input$x
}, valueFunc = function() {
print("value")
1
})
print(v$a())
})
}
shinyApp(ui, server)
如您所見,當selectInput值更改時,check函數內部的打印比以前評估n + 1次。
library(shiny)
ui <- fluidPage(selectInput("x", "Change options", c(1, 2)))
server <- function(input, output, session) {
v <- reactiveValues()
a <- reactivePoll(5000, session,
checkFunc = function() {
req(input$x)
print("test")
input$x
},
valueFunc = function() {
print("value")
1
}
)
observe({
print("obs")
req(input$x)
v$a <- a()
print(v$a)
})
}
shinyApp(ui, server)
要么
server <- function(input, output, session) {
v <- reactiveValues(
a = reactivePoll(5000, session,
checkFunc = function() {
req(input$x)
print("test")
input$x
},
valueFunc = function() {
print("value")
1
}
)
)
observe({
print("obs")
req(input$x)
print(v$a())
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.