如何将闪亮的动作按钮链接到R中的绘图动画?

如何将闪亮的动作按钮链接到R中的绘图动画?,r,animation,shiny,plotly,R,Animation,Shiny,Plotly,我试图用一个闪亮的动作按钮触发一个绘图仪的动画。 动画是在plotly中使用帧完成的。但是,这将创建一个触发动画的自动播放按钮。我不希望这个按钮存在,相反,我想用我创建的闪亮动作按钮触发动画 我尝试过将plotlyProxy与plotlyProxyInvoke(“动画”)函数一起使用,但没有成功 p <- plot_ly(sinusoid, x = ~time, y = ~sin, type = "scatter", mode = 'line', colors = colorRampPal

我试图用一个闪亮的动作按钮触发一个绘图仪的动画。 动画是在plotly中使用帧完成的。但是,这将创建一个触发动画的自动播放按钮。我不希望这个按钮存在,相反,我想用我创建的闪亮动作按钮触发动画

我尝试过将plotlyProxy与plotlyProxyInvoke(“动画”)函数一起使用,但没有成功

p <- plot_ly(sinusoid, x = ~time, y = ~sin, type = "scatter", mode = 'line',
colors = colorRampPalette(brewer.pal(5,"Spectral"))(50), hoverinfo = 'none',
name = "Cycle") %>%

add_markers(x = compUn$angleShift, y = compUn$sin, type = "scatter",
name = compUn$Country[i], showlegend = TRUE, marker = list(size = 12), 
frame = compUn$DateStringAdjusted, hoverinfo = 'text', 
text = paste0('D: ', round(compUn$D, 3), 
              '\nA: ', round(compUn$A, 3),
              '\nReturn: ', round(compUn$R, 3))) %>%

animation_opts(frame = 10000, redraw = FALSE)
p%
添加_标记(x=compUn$angleShift,y=compUn$sin,type=“scatter”,
name=compUn$Country[i],showlegend=TRUE,marker=list(size=12),
frame=compUn$DateStringAdjusted,hoverinfo='text',
text=paste0('D:',四舍五入(计算$D,3),
“\nA:”,圆形(计算$A,3),
“\n返回:”,四舍五入(计算$R,3))%>%
动画选择(帧=10000,重绘=FALSE)
单击闪亮的动作按钮后,最终的绘图动画应该是带有移动标记的静态正弦波。

库(闪亮)
library(shiny)
library(plotly)
library(htmlwidgets)

ui <- fluidPage(
  actionButton("anim", "Animate"),
  plotlyOutput("plot")
)

server <- function(input, output){
  output[["plot"]] <- renderPlotly({
    df <- data.frame(
      x = c(1,2,1), 
      y = c(1,2,1), 
      f = c(1,2,3)
    )
    df %>%
      plot_ly(
        x = ~x,
        y = ~y,
        frame = ~f,
        type = 'scatter',
        mode = 'markers',
        marker = list(size = 20),
        showlegend = FALSE
      ) %>% 
      animation_button(visible = FALSE) %>%
      onRender("
        function(el,x){
          $('#anim').on('click', function(){Plotly.animate(el);});
        }")

  })
}

shinyApp(ui, server)
图书馆(绘本) 库(htmlwidgets)
ui如果您提供正弦和计算机数据(和“i”),我可以尝试重现此问题。我相信你可以通过:animation_button(visible=F)隐藏默认的播放按钮——请看:谢谢,它成功了。不过,我还有一个问题。使用这种方法,animation_opts()参数不会影响帧的显示速率。我尝试更改动画_opts()的帧和间隔参数,但没有更改动画。是否必须在javascript代码中更改此设置是否可以在onRender()中编写一个函数,将plotly表格与已设置动画的plotly plot(通过plotly()中的参数帧设置动画)连接起来?我需要表格与绘图框架同时更改。我写了一篇帖子(stackoverflow.com/questions/58185641/…),但没有回答。你知道吗?也许有办法访问帧参数的当前值?例如,在这种情况下:根据当前所选滑块的值制作显示1、2或3的打印输出?