这个问题已经被问到here但是由于没有答案,我想我会发布另一个简单的例子,希望找到答案。
问题是当使用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))
}
)
答案 0 :(得分:5)
一切正常,你不能拥有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))
}
)