如何关闭在Plotly中显示我所有数据的工具提示?

时间:2018-06-21 11:42:52

标签: r ggplot2 shiny plotly r-plotly

我正在制作一个闪亮的仪表板应用程序。仪表板中的一个选项卡用于我的Plotly图。我能够很好地显示该图,但是每当我将鼠标光标停留在该图上一秒钟以上时,就会出现一个大量工具提示,该长度相当于显示器的长度,显示尽可能多的我的数据。这不是Plotly内置的悬停文本的一部分,它实际上很有用。这就像一个工具提示,当您将鼠标悬停在网络上的某个内容上时会显示。

This is a small part of the tooltip.

这显然是不可接受的。特别是因为此巨大的工具提示需要花费一秒钟或更长时间才能加载,所以它会使所有内容陷入瘫痪。如何关闭此功能?这很烦人,根本没有用。我认为解决方案与JS或HTML有关,但我不确定。任何帮助将不胜感激。预先感谢。

编辑:这是密谋。我使用ggplotly是因为我比使用plotly更熟悉使用ggplot自定义图。

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)

建议,这是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")

编辑:这是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 个答案:

答案 0 :(得分:2)

我无法重现您的问题。对我来说,它可以与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"))

它也可以处理您的数据。也许重新安装ggp​​lot2 / plotly ,然后重试。


将其绘制在 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 :(得分:0)

将工具提示设为空:

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

答案 2 :(得分:0)

在使用闪亮的应用程序的HTML进行深入挖掘之后,使用右键单击->检查,我能够看到我的tabPanel的标题以某种方式被分配为我的全部数据。这就是为什么将光标悬停在它上面导致它显示如此庞大的工具提示的原因。摆脱了tabPanel并将图放到tabItem中之后,我能够解决问题,删除了工具提示。

答案 3 :(得分:0)

@SeGa的答案对于控制工具提示文本非常有用,但是如果要完全隐藏工具提示,则可以将基础hoverinfo属性设置为"none"

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