Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中的javascript代码中更改plotly动画速度?_Javascript_R_Shiny_Plotly_R Plotly - Fatal编程技术网

如何在R中的javascript代码中更改plotly动画速度?

如何在R中的javascript代码中更改plotly动画速度?,javascript,r,shiny,plotly,r-plotly,Javascript,R,Shiny,Plotly,R Plotly,我想在R中更改plotly动画的速度。但是,plotly动画提供的默认播放按钮不会触发动画。根据JS代码,它是通过点击一个闪亮的动作按钮触发的。在这种情况下,似乎没有考虑animation_opts()参数 我尝试过更改动画的参数,如“frame”和“transition”,但动画保持不变。我还尝试在javascript代码中更改这些参数,但动画甚至没有启动 library(shiny) library(plotly) library(htmlwidgets) ui <- f

我想在R中更改plotly动画的速度。但是,plotly动画提供的默认播放按钮不会触发动画。根据JS代码,它是通过点击一个闪亮的动作按钮触发的。在这种情况下,似乎没有考虑animation_opts()参数

我尝试过更改动画的参数,如“frame”和“transition”,但动画保持不变。我还尝试在javascript代码中更改这些参数,但动画甚至没有启动

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_opts(frame = 5000, transition = 4500, redraw = FALSE) %>%
        animation_button(visible = FALSE) %>%
        onRender("
          function(el,x){
            $('#anim').on('click', function(){Plotly.animate(el);});
          }")

    })
  }

  shinyApp(ui, server)
库(闪亮)
图书馆(绘本)
库(htmlwidgets)
ui%
onRender(“
函数(el,x){
$('#anim').on('click',function(){Plotly.animate(el);});
}")
})
}
shinyApp(用户界面、服务器)

我想为plotly动画的帧和过渡持续时间设置一个参数,并能够在代码中对其进行更改。

以下是如何设置这些选项:

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_opts(frame = 5000, transition = 4500, redraw = FALSE) %>%
      animation_button(visible = FALSE) %>%
      onRender("
          function(el,x){
            $('#anim').on('click', function(){
              Plotly.animate(el, 
                null,
                {
                  transition: {
                    duration: 2000,
                    easing: 'cubic-in-out'
                  },
                  frame: {
                    duration: 2000
                  }
                }
              );
            });
          }")
  })
}

shinyApp(ui, server)
库(闪亮)
图书馆(绘本)
库(htmlwidgets)
ui%
onRender(“
函数(el,x){
$('#anim')。在('click',function()上{
绘制动画(el,
无效的
{
过渡:{
期限:2000年,
放松:“立方输入输出”
},
框架:{
持续时间:2000年
}
}
);
});
}")
})
}
shinyApp(用户界面、服务器)