File: app.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (4)
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
library(shiny)
library(plotly)
library(ggplot2)
library(promises)
library(future)
plan(multisession)

ui <- fluidPage(
  plotlyOutput("plot1"),
  plotlyOutput("plot2"),
  plotlyOutput("plot3"),
  plotlyOutput("plot4")
)

server <- function(input, output, session) {
  output$plot1 <- renderPlotly({
    # Async plot_ly
    future({ Sys.sleep(2); cars }) %...>%
      plot_ly(x = ~speed, y = ~dist, type = "scatter", mode = "markers")
  })
  
  output$plot2 <- renderPlotly({
    # Async ggplotly
    future({ Sys.sleep(2); mtcars }) %...>%
    { ggplot(., aes(hp, mpg)) + geom_point() } %...>%
      ggplotly()
  })
  
  output$plot3 <- renderPlotly({
    # Not async
    plot_ly(iris, x = ~Sepal.Length, y = ~Sepal.Width,
            type = "scatter", mode = "markers")
  })
  
  output$plot4 <- renderPlotly({
    # Ensure errors are handled properly (should be blank)
    future({}) %...>%
    { req(FALSE) }
  })
}

shinyApp(ui, server)