Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I remove hover from plotly graph produced with ggplotly or toWebGL

I have a shinyapp and use plotly-Plots. I have to use webGL, otherwise I do not get an acceptable performance. However it seems, the approach for removing hover here Remove hover info text from a plotly object does not work. My minimal example:

library(shiny)
library(ggplot2)
library(plotly)

ui <- fluidPage(
  plotlyOutput("po")
)

server <- function(input, output, session) {
  output$po <- renderPlotly({
    p <- ggplot(iris)+geom_point(aes(x=Sepal.Width,y=Sepal.Length,color=Species))
    p <- toWebGL(p)
    #p <- ggplotly(p) # This also does not work, so the problem seems to be somewhere else
    p$x$data[[1]]$hoverinfo <- "none"
    p
  })
}

shinyApp(ui, server)

The hover is still there. How can I remove it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I stripped away the shiny context as its still an issue you would have in a plain R script. The trick is to adjust the layout’s hover option (set to FALSE) ;
If theres a lot of text then you could do the optional line to remove the text from the plotly object.

library(ggplot2)
library(plotly)
p <- ggplot(iris)+geom_point(aes(x=Sepal.Width,y=Sepal.Length,color=Species))
p <- toWebGL(p)
p$x$layout$hovermode <- FALSE # This is what you want.
p$x$data[[1]]$text <- NULL # optional ; might make your plotly object smaller
p
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading