r语言 - 如何将selecticizeGroupInput与future_promise一起使用?



我正在使用一个未来的承诺来更有效地调用我的数据。然而,我发现我的过滤器(通过selecticizeGroupServer调用)不能与未来的承诺一起工作。

见附件中可重复的最小示例。当我删除"future_promise"时,过滤器按预期工作。函数从数据响应表达式。然而,当我使用&;future_promise,&;filter模块故障

你能帮我找出我做错了什么吗?

library(shiny)
library(future)
library(promises)
library(shinyWidgets)
plan(multisession)
ui <- fluidPage(
titlePanel("Example App"),
sidebarLayout(
sidebarPanel(),
mainPanel(
selectizeGroupUI(
id = "filters",
inline = FALSE,
params = list(
`mpg` = list(inputId = "mpg", title = "mpg", placeholder = "All"),
`cyl` = list(inputId = "cyl", title = "cyl", placeholder = "All"),
`disp` = list(inputId = "disp", title = "disp", placeholder = "All")
)
)
)
)
)
server <- function(input, output) {
data <- reactive({

future_promise({
mtcars
})
})
filter_mod <- reactive({})

observe({

filter_mod <<- callModule(
module = selectizeGroupServer,
id = "filters",
inline = FALSE,
data = data,
vars = c("mpg", "cyl", "disp")
)

})

}
# Run the application 
shinyApp(ui = ui, server = server)

我们可以使用初始化的reactiveVal代替reactive,以避免将承诺传递给selectizeGroupServer

请检查以下内容:

library(shiny)
library(future)
library(promises)
library(shinyWidgets)
plan(multisession)
ui <- fluidPage(
titlePanel("Example App"),
sidebarLayout(
sidebarPanel("The choices will appear after 5 seconds:"),
mainPanel(
selectizeGroupUI(
id = "filters",
inline = FALSE,
params = list(
`mpg` = list(inputId = "mpg", title = "mpg", placeholder = "All"),
`cyl` = list(inputId = "cyl", title = "cyl", placeholder = "All"),
`disp` = list(inputId = "disp", title = "disp", placeholder = "All")
)
)
)
)
)
server <- function(input, output, session) {
data <- reactiveVal(NULL)

future_promise({
Sys.sleep(5) # long running task
mtcars
}) %...>% data() # assign to reactiveVal "data" once the future_promise is resolved

filter_mod <- callModule(
module = selectizeGroupServer,
id = "filters",
inline = FALSE,
data = data,
vars = c("mpg", "cyl", "disp")
)
}
shinyApp(ui = ui, server = server)

相关内容

  • 没有找到相关文章

最新更新