2016-07-04 516 views
1

這個問題已被問到here但由於沒有答案,我想我會張貼另一個簡單的例子,希望找到答案。R閃亮的動態滑塊動畫

問題是滑動條使用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)) 

    } 
) 

這不起作用:

#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)) 

    } 
) 

回答

2

一切工作正常,你就不能有2周的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)) 

    } 
) 
+1

謝謝你的回答。此解決方案可以工作,現在可以通過輸入$ animationSlider2訪問滑塊的值。 –