Created
February 9, 2018 17:00
-
-
Save cpsievert/28a629df62674f2ac1db5ac59e566f77 to your computer and use it in GitHub Desktop.
Draw line shapes outlining brush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plotly) | |
library(crosstalk) | |
library(htmlwidgets) | |
mtcars %>% | |
SharedData$new() %>% | |
plot_ly(x = ~wt, y = ~mpg) %>% | |
highlight("plotly_selected", dynamic = TRUE) %>% | |
onRender( | |
"function(el, x) { | |
var gd = document.getElementById(el.id); | |
gd.on('plotly_selected', function(ed) { | |
var xmax = ed.range.x[1]; | |
var ymin = ed.range.y[0]; | |
var vline = {type: 'line', y0: 0, y1: 1, yref: 'paper', x0: xmax, x1: xmax, line: {dash: 'dot'}}; | |
var hline = {type: 'line', x0: 0, x1: 1, xref: 'paper', y0: ymin, y1: ymin, line: {dash: 'dot'}}; | |
Plotly.relayout(gd, {shapes: [vline, hline]}) | |
}) | |
}" | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment