-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshiny_async_pattern.R
More file actions
53 lines (45 loc) · 919 Bytes
/
Copy pathshiny_async_pattern.R
File metadata and controls
53 lines (45 loc) · 919 Bytes
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
## Minimal example, taken from http://blog.fellstat.com/?p=407
library(shiny)
library(promises)
library(future)
plan(multiprocess)
##
## UI part
##
ui <- fluidPage(
# Application title
titlePanel("Long Run Async"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
actionButton('run', 'Run')
),
# Show a plot of the generated distribution
mainPanel(
tableOutput("result")
)
)
)
##
## Server part
##
server <- function(input, output) {
# long running task
result_val <- reactiveVal()
observeEvent(input$run, {
result_val(NULL)
future({
print("Running...")
for(i in 1:10) {
Sys.sleep(1)
}
quantile(rnorm(1000))
}) %...>% result_val()
})
# fill UI with the results
output$result <- renderTable({
req(result_val())
})
}
# Run the application
shinyApp(ui = ui, server = server)