如何关闭在 Plotly 中显示我所有数据的工具提示?
How to turn off tooltip showing all of my data in Plotly?
我正在制作一个闪亮的仪表板应用程序。仪表板中的一个选项卡用于我的 Plotly 图。我能够让绘图显示得很好,但是每当我将鼠标光标放在绘图上超过一秒钟时,就会出现一个 大量工具提示 ,持续到我的长度监视器,显示尽可能多的我的数据。这不是 Plotly 内置的悬停文本的一部分,它实际上很有用。这就像将鼠标悬停在网络上的某个内容上时显示的工具提示。
显然这是不可接受的。特别是因为这个巨大的工具提示需要一秒钟或更长时间才能加载,所以它使一切陷入困境。我该如何关闭它?这很烦人而且一点用处也没有。我假设解决方案与 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
我无法重现您的问题。对我来说,它适用于 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"))
它也适用于您的数据输出。也许 重新安装 ggplot2 / 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)
})}
)
将工具提示设为空:
ggplotly(a, tooltip = c(""))
在我闪亮的应用程序的 HTML 中挖掘之后,使用右键单击 -> 检查,我能够看到我的 tabPanel 的标题以某种方式指定为我的全部数据。这就是为什么我的光标悬停在它上面会导致它显示如此巨大的工具提示。在摆脱 tabPanel 并将我的情节放入 tabItem 之后,我能够解决这个问题,删除工具提示。
@SeGa 的答案非常适合控制工具提示文本,但如果您想完全隐藏工具提示,则需要将基础 hoverinfo
属性设置为 "none"
style(ggplotly(plot), hoverinfo = "none")
我正在制作一个闪亮的仪表板应用程序。仪表板中的一个选项卡用于我的 Plotly 图。我能够让绘图显示得很好,但是每当我将鼠标光标放在绘图上超过一秒钟时,就会出现一个 大量工具提示 ,持续到我的长度监视器,显示尽可能多的我的数据。这不是 Plotly 内置的悬停文本的一部分,它实际上很有用。这就像将鼠标悬停在网络上的某个内容上时显示的工具提示。
显然这是不可接受的。特别是因为这个巨大的工具提示需要一秒钟或更长时间才能加载,所以它使一切陷入困境。我该如何关闭它?这很烦人而且一点用处也没有。我假设解决方案与 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
我无法重现您的问题。对我来说,它适用于 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"))
它也适用于您的数据输出。也许 重新安装 ggplot2 / 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)
})}
)
将工具提示设为空:
ggplotly(a, tooltip = c(""))
在我闪亮的应用程序的 HTML 中挖掘之后,使用右键单击 -> 检查,我能够看到我的 tabPanel 的标题以某种方式指定为我的全部数据。这就是为什么我的光标悬停在它上面会导致它显示如此巨大的工具提示。在摆脱 tabPanel 并将我的情节放入 tabItem 之后,我能够解决这个问题,删除工具提示。
@SeGa 的答案非常适合控制工具提示文本,但如果您想完全隐藏工具提示,则需要将基础 hoverinfo
属性设置为 "none"
style(ggplotly(plot), hoverinfo = "none")