R Shiny动态滑块动画

Tuo*_*nen 2 r shiny

这个问题已经在这里提出了,但是由于没有答案,我想我会再举一个简单的例子,以期找到答案。

问题是,当使用renderUI()动态构建滑块时,sliderInput()的动画选项不起作用。

因此,尽管这很好用:

# works 
library(shiny)

shinyApp(

  ui = fluidPage(

    sliderInput("animationSlider", "non-dynamic animation slider", 
                min = 1, max = 100, value = 1, step = 1,
                animate = animationOptions(200)),

    textOutput("sliderValue")

  ),

  server = function(input, output) {

    output$sliderValue <- renderText(paste("value:", input$animationSlider))

  }
)
Run Code Online (Sandbox Code Playgroud)

这不起作用:

#doesn't work
library(shiny)

shinyApp(

  ui = fluidPage(

    numericInput("max", "Set max value for dynamic animation slider", 
                value = 10),
    uiOutput("animationSlider"),
    textOutput("sliderValue")

  ),

  server = function(input, output) {

    output$animationSlider <- renderUI({
      sliderInput("animationSlider", "Dynamic animation slider", 
                  min = 1, max = input$max, value = 1, step = 1,
                  animate = animationOptions(200))
    })

    output$sliderValue <- renderText(paste("value:", input$animationSlider))

  }
)
Run Code Online (Sandbox Code Playgroud)

Por*_*hop 5

一切正常,您不能有两个具有相同名称的div:

library(shiny)

shinyApp(

  ui = fluidPage(

    numericInput("max", "Set max value for dynamic animation slider", 
                 value = 10),
    uiOutput("animationSlider"),
    textOutput("sliderValue")

  ),

  server = function(input, output) {

    output$animationSlider <- renderUI({
      sliderInput("animationSlider2", "Dynamic animation slider", 
                  min = 1, max = input$max, value = 1, step = 1,
                  animate = animationOptions(200))
    })

    output$sliderValue <- renderText(paste("value:", input$animationSlider2))

  }
)
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你的回答。此解决方案有效,现在可以通过 input$animationSlider2 访问滑块的值。 (2认同)