-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathapp.R
More file actions
70 lines (58 loc) · 1.46 KB
/
app.R
File metadata and controls
70 lines (58 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
library(shiny)
yoink <- function(pkg, fn_name) {
getFromNamespace(fn_name, pkg)
}
promise <- yoink("promises", "promise")
later <- yoink("later", "later")
input_task_button <- yoink("bslib", "input_task_button")
bind_task_button <- yoink("bslib", "bind_task_button")
ui <- fluidPage(
actionButton("run_normal", "Run normal"),
textOutput("normal_result"),
input_task_button("run_async", "Run async"),
textOutput("async_result")
)
server <- function(input, output, session) {
returned_value <- reactiveValues()
slow_function <- function() {
return(10)
}
task <- ExtendedTask$new(function() {
promise(function(resolve, reject) {
# Use later to simulate future promise calls
later(
function() {
resolve(slow_function())
# Add extra time for extra checks
},
delay = 0.01
)
})
}) |>
bind_task_button("run_async")
# Normal
observeEvent(input$run_normal, {
returned_value$normal <- slow_function()
})
output$normal_result <- renderText({
req(returned_value$normal)
returned_value$normal
})
# Async
observeEvent(input$run_async, {
task$invoke()
})
observe({
returned_value$async <- task$result()
})
output$async_result <- renderText({
req(returned_value$async)
returned_value$async
})
# Export for testing
exportTestValues(
async = returned_value$async,
normal = returned_value$normal
)
}
shinyApp(ui = ui, server = server)