File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
inst/examples/shiny/async Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ library(shiny )
2+ library(plotly )
3+ library(ggplot2 )
4+ library(promises )
5+ library(future )
6+ plan(multisession )
7+
8+ ui <- fluidPage(
9+ plotlyOutput(" plot1" ),
10+ plotlyOutput(" plot2" ),
11+ plotlyOutput(" plot3" ),
12+ plotlyOutput(" plot4" )
13+ )
14+
15+ server <- function (input , output , session ) {
16+ output $ plot1 <- renderPlotly({
17+ # Async plot_ly
18+ future({ Sys.sleep(2 ); cars }) %... > %
19+ plot_ly(x = ~ speed , y = ~ dist , type = " scatter" , mode = " markers" )
20+ })
21+
22+ output $ plot2 <- renderPlotly({
23+ # Async ggplotly
24+ future({ Sys.sleep(2 ); mtcars }) %... > %
25+ { ggplot(. , aes(hp , mpg )) + geom_point() } %... > %
26+ ggplotly()
27+ })
28+
29+ output $ plot3 <- renderPlotly({
30+ # Not async
31+ plot_ly(iris , x = ~ Sepal.Length , y = ~ Sepal.Width ,
32+ type = " scatter" , mode = " markers" )
33+ })
34+
35+ output $ plot4 <- renderPlotly({
36+ # Ensure errors are handled properly (should be blank)
37+ future({}) %... > %
38+ { req(FALSE ) }
39+ })
40+ }
41+
42+ shinyApp(ui , server )
You can’t perform that action at this time.
0 commit comments