4
votes

I am making a shiny dashboard application. One of the Tabs in the dashboard is for my Plotly plot. I am able to get the plot to show up just fine, but whenever I leave my mouse's cursor over the plot for more than a second, a massive tooltip shows up, going the length of my monitor, that displays as much of my data as can fit. This is not part of Plotly's built in hover text, which is actually useful. This is like a tooltip that shows when you hover over something on the web.

This is a small part of the tooltip.

Obviously this is unacceptable. Especially because this huge tooltip takes a second or more to load, so it bogs everything down. How do I turn this off? It's annoying and not useful at all. I assume the solution is JS or HTML related but I am not sure. Any help would be greatly appreciated. Thanks in advance.

EDIT: Here is the plotly call. I use ggplotly because I am more familiar with customizing the plot using ggplot than plotly.

library(plotly)     

plot <- ggplot(mydata) + geom_ribbon(aes(ymin = obsAcc25, ymax = obsAcc97, x = x), fill = "cadetblue3", alpha = 0.8) 
    + geom_ribbon(aes(ymin = delAcc25, ymax = delAcc97, x = x), fill = "palegreen3", alpha = 0.8) 
    + geom_ribbon(aes(ymin = actAcc25, ymax = actAcc97, x = x), fill = "dodgerblue4", alpha = 0.8) 
    + theme(panel.grid.major = element_line(color = "grey58"), panel.grid.minor = element_line(color = "grey75"))


    p <- ggplotly(plot)

As was suggested, here is dput(head(mydata, 10))

structure(list(actAcc25 = c(-12.8684282283388, -12.0304436152616, 
-11.3150952252788, -10.6081847586627, -10.0552821849214, -9.55261456431379, 
-9.04799817226408, -8.63169310666002, -8.21986707344882, -7.87700068972389
), obsAcc25 = c(-29.2405337619969, -28.8889501014795, -28.504360142198, 
-28.1674808122894, -27.8980268120593, -27.5944378874029, -27.2407785909855, 
-26.9557048837549, -26.8112580628704, -26.3946724698358), delAcc25 = c(-13.2454526253711, 
-12.3943001876792, -11.7223680727026, -11.0627967149018, -10.5171275099291, 
-10.0121757711887, -9.55927026173585, -9.15474795930365, -8.7615554644258, 
-8.44377029372532), actAcc97 = c(20.5859080152232, 19.5383979476408, 
18.5967498955669, 17.9042117055988, 17.1661035121933, 16.5672919339584, 
16.0108793011971, 15.4856795165235, 15.0292972125609, 14.5904142938209
), obsAcc97 = c(39.5176394183119, 38.6324722217456, 37.9015992542866, 
37.2607649650388, 36.681699119323, 36.1958973938439, 35.6469528390747, 
35.336998047658, 34.9088544137054, 34.4801441415), delAcc97 = c(21.0663356298793, 
20.103870882492, 19.2051147569388, 18.513845516169, 17.7970734480676, 
17.1961361293244, 16.650452469565, 16.1799047501671, 15.7202776795709, 
15.2788029123616), x = c(0.4486530314, 0.5103655236, 0.5760397998, 
0.6456734834, 0.7192641994, 0.7968095744, 0.8783072362, 0.9637548142, 
1.053149939, 1.146490243)), row.names = c(NA, 10L), class = "data.frame")

EDIT: and here is the output of sessionInfo()

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dashboardthemes_1.0.2 plotly_4.7.1          ggplot2_2.2.1         shinydashboard_0.7.0  shiny_1.1.0          

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17      pillar_1.2.3      compiler_3.5.0    later_0.7.3       plyr_1.8.4        bindr_0.1.1       shinyjs_1.0       tools_3.5.0      
 [9] digest_0.6.15     viridisLite_0.3.0 jsonlite_1.5      tibble_1.4.2      gtable_0.2.0      pkgconfig_2.0.1   rlang_0.2.1       crosstalk_1.0.0  
[17] yaml_2.1.19       bindrcpp_0.2.2    dplyr_0.7.5       httr_1.3.1        htmlwidgets_1.2   grid_3.5.0        tidyselect_0.2.4  glue_1.2.0       
[25] data.table_1.11.4 R6_2.2.2          tidyr_0.8.1       purrr_0.2.5       magrittr_1.5      scales_0.5.0      promises_1.0.1    htmltools_0.3.6  
[33] rsconnect_0.8.8   assertthat_0.2.0  mime_0.5          xtable_1.8-2      colorspace_1.3-2  httpuv_1.4.3      labeling_0.3      lazyeval_0.2.1   
[41] munsell_0.5.0
4
Could you include a small example??SeGa
@SeGa Edited with my ggplotly call.skippy_winks
Your example should be reproducible. Include (using dput) mydata in your post.MLavoie
@MLavoie how do you mean? Sorry, I am unfamiliar with making this example reproducible. I can add more information about mydata if that would help?skippy_winks
it could be dput(head(yourdata, 10)).MLavoie

4 Answers

3
votes

I am not able to reproduce your problem. For me it works with tooltip = FALSE.

library(ggplot2)
library(plotly)

n=10
mydata <- data.frame(
  obsAcc25 = runif(n, 1, 10),
  obsAcc97 = runif(n, 1, 10),
  delAcc25 = runif(n, 1, 10),
  delAcc97 = runif(n, 1, 10),
  actAcc25 = runif(n, 1, 10),
  actAcc97 = runif(n, 1, 10),
  x = runif(n, 1, 10)
)

plot <- ggplot(mydata) + geom_ribbon(aes(ymin = obsAcc25, ymax = obsAcc97, x = x), fill = "cadetblue3", alpha = 0.8) +
 geom_ribbon(aes(ymin = delAcc25, ymax = delAcc97, x = x), fill = "palegreen3", alpha = 0.8) +
 geom_ribbon(aes(ymin = actAcc25, ymax = actAcc97, x = x), fill = "dodgerblue4", alpha = 0.8) +
 theme(panel.grid.major = element_line(color = "grey58"), panel.grid.minor = element_line(color = "grey75"))

## No Toolstips at all
ggplotly(plot, tooltip = NULL)

## just the ymin from the aes is taken as label
ggplotly(plot, tooltip = c("ymin"))

## Ymin/Ymax and X are taken as label.
ggplotly(plot, tooltip = c("ymin", "ymax", "x"))

It also works with the dput of your data. Maybe reinstall ggplot2 / plotly and try again.


Plotting it in a shinydashboard:

library(shiny)
library(shinydashboard)

shinyApp(
  ui = dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
      plotlyOutput("plot")
    )
  ),
  server = function(input, output) { 
    output$plot <- renderPlotly({
      plot <- ggplot(mydata) + geom_ribbon(aes(ymin = obsAcc25, ymax = obsAcc97, x = x), fill = "cadetblue3", alpha = 0.8) +
        geom_ribbon(aes(ymin = delAcc25, ymax = delAcc97, x = x), fill = "palegreen3", alpha = 0.8) +
        geom_ribbon(aes(ymin = actAcc25, ymax = actAcc97, x = x), fill = "dodgerblue4", alpha = 0.8) +
        theme(panel.grid.major = element_line(color = "grey58"), panel.grid.minor = element_line(color = "grey75"))
      ggplotly(plot, tooltip = NULL)
    })}
)
1
votes

Put the tooltip null:

ggplotly(a, tooltip = c(""))
1
votes

@SeGa's answer is a great for controlling the tooltip text, but if you want to completely hide the tooltip would be to set the underlying hoverinfo attribute to "none"

style(ggplotly(plot), hoverinfo = "none")
0
votes

After digging around in the HTML of my shiny app, using Right Click -> Inspect, I was able to see that the title for my tabPanel was somehow assigned to be the entirety of my data. This is why hovering over it with my cursor caused it to display such a massive tooltip. After getting rid of the tabPanel and just putting my plot in tabItem, I was able to fix the issue, removing the tooltip.