- 已编辑
如题,如何在 plotly 绘制的网页动画中再添加一个暂停按钮,下面是一个示例,基于 gapminder 数据集
library(plotly)
library(gapminder)
plot_ly( data = gapminder,
x = ~gdpPercap, y = ~lifeExp, size = ~pop, frame = ~year,
text = ~country, color = ~continent, ids = ~country,
hoverinfo = "text", type = "scatter", mode = "markers",
marker = list(
symbol = "circle", sizemode = "diameter", opacity = 0.4
)
) %>%
animation_opts(easing = "linear", redraw = FALSE, frame = 500) %>%
animation_button(
label = "播放",
visible = TRUE,
method = "animate",
x = 1, xanchor = "right",
y = 1, yanchor = "bottom"
) %>%
animation_slider(
currentvalue = list(prefix = "日期 ", font = list(color = "red"))
) %>%
config(displayModeBar = F)
效果如视频
视频中已经有一个播放按钮了,如何添加一个暂停按钮,实现随时暂停播放?
认真看了 R 包 plotly 的 animation_button 函数和帮助文档 https://github.com/ropensci/plotly/blob/master/R/animate.R#L156
也巡着帮助文档看了 Plotly.js 库的相关代码 https://github.com/plotly/plotly.js/blob/master/src/components/updatemenus/attributes.js
还是没有搞明白,如何再添加一个暂停按钮,求助大家
P.S.
https://plotly.com/python/animations/
https://plotly.com/javascript/gapminder-example/