【问题标题】:R Shiny animated slider with renderUIR Shiny 带有 renderUI 的动画滑块
【发布时间】:2015-04-15 20:45:49
【问题描述】:

我想根据单选按钮的输入值设置滑块的动态最小值和最大值。现在我可以使用 renderUI 选项来做到这一点,我在 server.ui 中设置了我的最小值和最大值,并且这些值是动态设置的。

但是当我将动画选项放在渲染UI 中时,它无法正常工作。在我的 ui.r 中,我有以下代码。

radioButtons("interval", "Time Interval:", 
             c("Day of the week"="%u","Day of the month" = "%d", "Week of the year" = "%W", "Month of the year" = "%m","Quarter of the year"="quarter","year"="%y")) 
,uiOutput("Slider")

在我的 server.r 中,我设置了如下值。

order$date_of_month<-as.numeric(format(as.Date(order$Date.Ordered), interval)) 
output$Slider<-renderUI({
  sliderInput("date_range", "Date Range", min = 2,
              max = max(order$date_of_month), value = max(order$date_of_month)
              ,step = 1
              ,animate = animationOptions(loop = TRUE, interval = 5000))
})



radioButtons("interval", "Time Interval:", 
             c("Day of the week"="%u","Day of the month" = "%d", 
               "Week of the year" = "%W", "Month of the year" = "%m","Quarter of the year"="quarter","year"="%y")) 
,uiOutput("Slider")

【问题讨论】:

  • 我这里似乎也有同样的问题。自从您发布问题后,您是否设法找到解决此问题的方法/解决方法?

标签: r animation slider shiny


【解决方案1】:

尝试用这个替换你当前的滑块功能:

output$Slider<-renderUI({
  date_of_month<-as.numeric(format(as.Date(order$Date.Ordered), input$interval)) 
  sliderInput("date_range", "Date Range", min = 2,
              max = max(date_of_month), value = max(date_of_month)
              ,step = 1
              ,animate = animationOptions(loop = TRUE, interval = 5000))
})
  1. 使用input$interval 而不是interval 来访问输入值。
  2. date_of_month 的计算移到renderUI 函数中,以便它对input$interval 的变化作出反应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 2014-07-29
    • 2021-08-28
    • 2015-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多