Skip to content

Commit 1587f90

Browse files
committed
improve event_data shine example apps
1 parent 6b9ae36 commit 1587f90

File tree

2 files changed

+35
-15
lines changed
  • inst/examples/shiny

2 files changed

+35
-15
lines changed

inst/examples/shiny/event_data/app.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ ui <- fluidPage(
66
plotlyOutput("plot"),
77
verbatimTextOutput("hover"),
88
verbatimTextOutput("click"),
9-
verbatimTextOutput("selected"),
9+
verbatimTextOutput("brushing"),
1010
verbatimTextOutput("selecting"),
1111
verbatimTextOutput("brushed"),
12-
verbatimTextOutput("brushing")
12+
verbatimTextOutput("selected")
1313
)
1414

1515
server <- function(input, output, session) {
@@ -37,24 +37,24 @@ server <- function(input, output, session) {
3737
if (is.null(d)) "Click events appear here (double-click to clear)" else d
3838
})
3939

40-
output$selected <- renderPrint({
41-
d <- event_data("plotly_selected")
42-
if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
40+
output$brushing <- renderPrint({
41+
d <- event_data("plotly_brushing")
42+
if (is.null(d)) "Brush extents appear here (double-click to clear)" else d
4343
})
4444

4545
output$selecting <- renderPrint({
4646
d <- event_data("plotly_selecting")
47-
if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
47+
if (is.null(d)) "Brush points appear here (double-click to clear)" else d
4848
})
4949

5050
output$brushed <- renderPrint({
5151
d <- event_data("plotly_brushed")
52-
if (is.null(d)) "Extents of the selection brush will appear here." else d
52+
if (is.null(d)) "Brush extents appear here (double-click to clear)" else d
5353
})
5454

55-
output$brushing <- renderPrint({
56-
d <- event_data("plotly_brushing")
57-
if (is.null(d)) "Extents of the selection brush will appear here." else d
55+
output$selected <- renderPrint({
56+
d <- event_data("plotly_selected")
57+
if (is.null(d)) "Brushed points appear here (double-click to clear)" else d
5858
})
5959

6060
}
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
1-
library(shiny)
21
library(plotly)
2+
library(shiny)
33

44
ui <- fluidPage(
55
plotlyOutput("plot"),
66
verbatimTextOutput("hover"),
7-
verbatimTextOutput("click")
7+
verbatimTextOutput("click"),
8+
verbatimTextOutput("legendclick"),
9+
verbatimTextOutput("legend2click"),
10+
verbatimTextOutput("relayout")
811
)
912

1013
server <- function(input, output, session) {
1114

1215
output$plot <- renderPlotly({
13-
plot_ly(x = rnorm(10), y = rnorm(10), z = rnorm(10), type = "scatter3d")
16+
plot_ly(mtcars, x = ~wt, y = ~mpg, z = ~disp, color = ~factor(cyl)) %>%
17+
event_register("plotly_legendclick") %>%
18+
event_register("plotly_legenddoubleclick")
1419
})
1520

1621
output$hover <- renderPrint({
1722
d <- event_data("plotly_hover")
18-
if (is.null(d)) "Hover events appear here (unhover to clear)" else d
23+
if (is.null(d)) "Hover events appear here" else d
1924
})
2025

2126
output$click <- renderPrint({
2227
d <- event_data("plotly_click")
2328
if (is.null(d)) "Click events appear here" else d
2429
})
2530

31+
output$legendclick <- renderPrint({
32+
d <- event_data("plotly_legendclick")$name
33+
if (is.null(d)) "Legend click" else d
34+
})
35+
36+
output$legend2click <- renderPrint({
37+
d <- event_data("plotly_legenddoubleclick")$name
38+
if (is.null(d)) "Legend double-click" else d
39+
})
40+
41+
output$relayout <- renderPrint({
42+
d <- event_data("plotly_relayout")$scene.camera$eye
43+
if (is.null(d)) "Camera eye info" else d
44+
})
45+
2646
}
2747

28-
shinyApp(ui, server, options = list(display.mode = "showcase"))
48+
shinyApp(ui, server)

0 commit comments

Comments
 (0)