Search code examples
rcursorplotly

R plotly, normal cursor when mouse over the plot


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


Solution

  • 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')
    }
    ")