Skip to content

Commit ddf7adb

Browse files
committed
Merge branch 'master' into sizemode-pixel
2 parents 7e00673 + 572d065 commit ddf7adb

File tree

10 files changed

+107
-27
lines changed

10 files changed

+107
-27
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
}

inst/examples/shiny/event_data/tests/mytest-expected/001.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"plotType": "ggplotly"
44
},
55
"output": {
6-
"brushed": "[1] \"Extents of the selection brush will appear here.\"",
7-
"brushing": "[1] \"Extents of the selection brush will appear here.\"",
6+
"brushed": "[1] \"Brush extents appear here (double-click to clear)\"",
7+
"brushing": "[1] \"Brush extents appear here (double-click to clear)\"",
88
"click": "[1] \"Click events appear here (double-click to clear)\"",
99
"hover": "[1] \"Hover events appear here (unhover to clear)\"",
1010
"plot": {
@@ -449,8 +449,8 @@
449449
}
450450
]
451451
},
452-
"selected": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\"",
453-
"selecting": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\""
452+
"selected": "[1] \"Brushed points appear here (double-click to clear)\"",
453+
"selecting": "[1] \"Brush points appear here (double-click to clear)\""
454454
},
455455
"export": {
456456

-2.15 KB
Loading

inst/examples/shiny/event_data/tests/mytest-expected/002.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"plotType": "ggplotly"
2121
},
2222
"output": {
23-
"brushed": "[1] \"Extents of the selection brush will appear here.\"",
24-
"brushing": "[1] \"Extents of the selection brush will appear here.\"",
23+
"brushed": "[1] \"Brush extents appear here (double-click to clear)\"",
24+
"brushing": "[1] \"Brush extents appear here (double-click to clear)\"",
2525
"click": " curveNumber pointNumber x y customdata\n1 0 7 24.4 3.19 Merc 240D",
2626
"hover": "[1] \"Hover events appear here (unhover to clear)\"",
2727
"plot": {
@@ -466,8 +466,8 @@
466466
}
467467
]
468468
},
469-
"selected": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\"",
470-
"selecting": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\""
469+
"selected": "[1] \"Brushed points appear here (double-click to clear)\"",
470+
"selecting": "[1] \"Brush points appear here (double-click to clear)\""
471471
},
472472
"export": {
473473

-2.2 KB
Loading
170 Bytes
Loading

inst/examples/shiny/event_data/tests/mytest-expected/004.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"plotType": "ggplotly"
2626
},
2727
"output": {
28-
"brushed": "[1] \"Extents of the selection brush will appear here.\"",
29-
"brushing": "[1] \"Extents of the selection brush will appear here.\"",
28+
"brushed": "[1] \"Brush extents appear here (double-click to clear)\"",
29+
"brushing": "[1] \"Brush extents appear here (double-click to clear)\"",
3030
"click": "[1] \"Click events appear here (double-click to clear)\"",
3131
"hover": "[1] \"Hover events appear here (unhover to clear)\"",
3232
"plot": {
@@ -471,8 +471,8 @@
471471
}
472472
]
473473
},
474-
"selected": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\"",
475-
"selecting": "[1] \"Click and drag events (i.e., select/lasso) appear here (double-click to clear)\""
474+
"selected": "[1] \"Brushed points appear here (double-click to clear)\"",
475+
"selecting": "[1] \"Brush points appear here (double-click to clear)\""
476476
},
477477
"export": {
478478

-2.15 KB
Loading
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)

inst/examples/shiny/stream/app.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
library(shiny)
2+
library(plotly)
3+
4+
ui <- fluidPage(
5+
actionButton("stream", "Turn stream on/off"),
6+
plotlyOutput("plot")
7+
)
8+
9+
server <- function(input, output, session) {
10+
11+
# initial values
12+
yint <- c(0, 1)
13+
14+
# initiate graph with initial values
15+
output$plot <- renderPlotly({
16+
plot_ly(y = yint, x = seq_along(yint)) %>%
17+
add_lines()
18+
})
19+
20+
# reactiveValues() act very much like input values, but may be used to
21+
# maintain state (e.g., are we currently streaming?)
22+
rv <- reactiveValues(
23+
stream = FALSE,
24+
yend = sum(yint),
25+
n = length(yint)
26+
)
27+
28+
# turn streaming on/off when the button is pressed
29+
observeEvent(input$stream, {
30+
rv$stream <- if (rv$stream) FALSE else TRUE
31+
})
32+
33+
observe({
34+
# if we're not streaming, don't do anything
35+
if (!rv$stream) return()
36+
37+
# re-execute this code block to every 100 milliseconds
38+
invalidateLater(100, session)
39+
# changing a reactive value "invalidates" it, so isolate() is needed
40+
# to avoid recursion
41+
isolate({
42+
rv$n <- rv$n + 1
43+
rv$yend <- rv$yend + sample(c(-1, 1), 1)
44+
})
45+
46+
# add the new value to the plot
47+
plotlyProxy("plot", session) %>%
48+
plotlyProxyInvoke(
49+
"extendTraces",
50+
list(
51+
y = list(list(rv$yend)),
52+
x = list(list(rv$n))
53+
),
54+
list(0)
55+
)
56+
})
57+
58+
}
59+
60+
shinyApp(ui, server)

0 commit comments

Comments
 (0)