Skip to content

Commit 9fc41db

Browse files
committed
add shiny example of crossfilter with scatterplot
1 parent 70f67c3 commit 9fc41db

File tree

1 file changed

+39
-0
lines changed
  • inst/examples/shiny/crossfilter_scatter

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
library(shiny)
2+
library(plotly)
3+
library(dplyr)
4+
5+
ui <- fluidPage(
6+
plotlyOutput("bars"),
7+
plotlyOutput("markers")
8+
)
9+
10+
server <- function(input, output, session) {
11+
12+
output$bars <- renderPlotly({
13+
plot_ly(diamonds, x = ~depth, source = "bars") %>%
14+
layout(
15+
dragmode = "select",
16+
selectdirection = "h"
17+
)
18+
})
19+
20+
output$markers <- renderPlotly({
21+
plot_ly(diamonds, x = ~carat, y = ~price, alpha = 0.2) %>%
22+
toWebGL()
23+
})
24+
25+
observe({
26+
brush <- event_data("plotly_brushing", source = "bars")
27+
if (is.null(brush)) brush <- list(x = range(diamonds$depth))
28+
29+
is_within <- between(diamonds$depth, brush$x[1], brush$x[2])
30+
cols <- if_else(is_within, "rgba(31,119,180,0.2)", "transparent")
31+
32+
plotlyProxy("markers", session) %>%
33+
plotlyProxyInvoke("restyle", "marker.color", list(cols))
34+
})
35+
36+
37+
}
38+
39+
shinyApp(ui, server)

0 commit comments

Comments
 (0)