Hello,
I post a reprex about an issue I meet.
I try to combine buttons and an animation. The buttons are EXPORT and IMPORT.
Let’s click on the IMPORT button and play the animation. The statistics are coming back to EXPORT and the colorscale to orange. Same problem if I move the period, plotly uses default parameters.
How can I make the buttons and the frame “communicate” ? In other words, pass the selected choice of updatemenus to the animation ?
Thank you for your help.
library(tidyverse)
library(plotly)
Trade=data.frame(PERIOD=c(2017:2020),
CODE=rep("USA",4),
EXPORT=c(5761404,6908563,11071009,9160132),
IMPORT=c(6378023,6730260,6461171,3283063))
colorscale1=list(c(0,"white"),c(1,"#efaa22"))
colorscale2=list(c(0,"white"),c(1,"#902147"))
plot_geo(Trade) %>%
add_trace(locations = ~CODE,
frame = ~PERIOD,
z = ~EXPORT,
zmin = 0,
zmax = max(Trade$EXPORT),
color = ~EXPORT,
colorscale = colorscale1
) %>%
layout(
updatemenus = list(
list(active=0,type="buttons",
buttons = list(
list(method = "restyle",
args = list(list(z=list(~EXPORT),color=list(~EXPORT),
zmax=list(max(Trade$EXPORT)),
zmin=list(0),
colorscale=list(colorscale1),
colorbar.title="EXPORT")),
label = "Export"),
list(method = "restyle",
args = list(list(z=list(~IMPORT),color=list(~IMPORT),
zmax=list(max(Trade$IMPORT)),
zmin=list(0),
colorscale=list(colorscale2),
colorbar.title="IMPORT")),
label = "Import")
)
)
)
)