代码之家  ›  专栏  ›  技术社区  ›  user20650

闪亮的动画点图

  •  1
  • user20650  · 技术社区  · 7 年前

    你能建议一种方法来添加一个动画点图/条带图吗 shiny

    我想补充的数字是

    x = sample(1:10, 100, TRUE)
    
    for(i in seq_along(x)){
      stripchart(x[1:i], method="stack", at=0.05, frame.plot=FALSE, xaxt="n", xlim=range(x))
      axis(1, pretty(x))
      Sys.sleep(0.05)
    }
    

    (理想情况下,我希望它比0.05快,但R baulks)

    闪亮的 ( ggplotly doesn't seem like an option )


    闪亮的 代码:

    library(shiny)
    
    ui = fluidPage( plotOutput("plot") )
    
    server = function(input, output, session) {
      x = sample(1:10, 100, TRUE)
      rng = range(x)
      output$plot <- renderPlot({
          for(i in seq_along(x)){
          stripchart(x[1:i], method="stack", at=0.05, frame.plot=FALSE, 
                     pch=16, cex=2, xaxt="n", xlim=rng)
          axis(1, pretty(x))
          Sys.sleep(0.05)
          }})}
    
    shinyApp(ui = ui, server = server)
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   user20650    7 年前

    遵循Stphane Laurent的建议使用 sliders stripchart .

    library(shiny)
    
    ui <- fluidPage(    
      titlePanel("Sliders"),
      sidebarLayout(
        sidebarPanel(
          sliderInput("animation", "Looping Animation:",
                      min = 0, max = 100,
                      value = 1, step = 10,
                      animate = animationOptions(interval = 300, loop = FALSE))
        ),
        mainPanel(plotOutput("plot"))
        ))
    
    server <- function(input, output) {
    
      x = sample(1:10, 100, TRUE)
    
      sliderValues <- reactive({ (input$animation)})
    
      output$plot <- renderPlot({
          stripchart(x[1:sliderValues()], method="stack", at=0.05, frame.plot=FALSE, 
               pch=16, cex=2, xaxt="n", xlim=range(x))
          axis(1, pretty(x))
      })    
    }
    
    # Create Shiny app ----
    shinyApp(ui, server)
    
    推荐文章