(这是对this question的跟进。)
我正在构建一个带有多个用于绘制分布参数的滑块的Shiny应用程序。但是,我找不到将“活动”动画的数量限制为一个滑块的选项。
是否可以在激活另一个滑块时自动停止一个滑块的动画?
同时播放多个滑块动画不仅看起来不好,而且还会降低应用速度。
MWE:
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)