代码之家  ›  专栏  ›  技术社区  ›  Frans Rodenburg

每次将闪亮滑块动画的数量限制为一个

  •  1
  • Frans Rodenburg  · 技术社区  · 7 年前

    (这是对 this question .)

    我正在构建一个闪亮的应用程序,其中有多个滑块用于绘制分布的参数。但是,我找不到将“活动”动画的数量限制为 滑杆。

    当一个滑块被激活时,是否可以自动停止另一个滑块的动画?

    在我看来,同时打开多个滑块动画不仅看起来不好,而且会减慢应用程序的速度。

    library(shiny)
    
    ui <- fluidPage(
    
      ### SLIDER 1 ###
      shinyWidgets::sliderTextInput(
        "mu","Mean", choices = (-99:99)/10, selected = 0, grid = TRUE, 
        animate = animationOptions(interval = 100, loop = TRUE)),
    
      ### SLIDER 2 ###
      shinyWidgets::sliderTextInput(
        "sigma","Variance", selected = 1, grid = TRUE, 
        choices = apply(expand.grid(1:10, 10^(-2:2)), 1, prod),
        animate = animationOptions(interval = 100, loop = TRUE)),
    
      plotOutput("plot")
    )
    
    server <- function(input, output) {
    
      ### PLOT ###
      output$plot <- renderPlot({
        x <- seq(-10, 10, 0.01)
        plot(dnorm(x, input$mu, input$sigma) ~ x, type = 'l', yaxs = 'i',
             xlim = c(-9, 9), ylim = c(0, 1/input$sigma/2),
             ylab = 'Probability density')
      })
    }
    
    shinyApp(ui, server)
    
    0 回复  |  直到 7 年前