[英]R Shiny animated slider with renderUI
我想根据单选按钮的输入值设置滑块的动态最小值和最大值。 现在,我可以使用renderUI选项执行此操作,可以在server.ui中设置最小值和最大值,并且可以动态设置值。
但是,当我将动画选项放在renderUI中时,它不能正常工作。 在我的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")
尝试用以下方法替换当前的滑块功能:
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))
})
input$interval
而不是interval
来访问输入值。 date_of_month
的计算移动到renderUI
函数中,以便对input$interval
更改起反应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.