R plotly, normal cursor when mouse over the plot

2019-06-11 13:17发布

问题:

In plotly by default when the mouse is over the graph cursor changes to "pointer", any idea how to keep the normal cursor?

回答1:

Bit of a hacky solution but you can use htmlwidgets and Javascript to specify the cursor yourself.

Via d3.select we get all elements where the cursor-crosshair class is used and overwrite the cursor setting to default, therefore all other cursors are untouched, e.g. the resize cursor for the axes.

library(plotly)
library(htmlwidgets)

plot_ly(type='bar', 
             x = c(1, 2), 
             y = c(3, 5)) %>% onRender("
function(el, x) {
  Plotly.d3.select('.cursor-crosshair').style('cursor', 'default')
}
")


标签: r cursor plotly