本文介绍了R带有renderUI的闪亮动画滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据单选按钮的输入值设置滑块的动态最小值和最大值。现在我可以使用renderUI选项做到这一点,我在server.ui中设置了最小值和最大值,并且值是动态设置的。
I wanted to set dynamic minimum and maximum values for the slider based on the input value of a radio button. Now I was able to do this using renderUI option, I set my min and max values in the server.ui and values are set dynamically.
但是当我放置动画选项时在renderUI中无法正常工作。在我的ui.r中,我有以下代码。
But when I put animation options inside the renderUI that does not work properly. In my ui.r I have following codes.
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中,我的值设置如下。
And in my server.r I have set values as follows.
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")
推荐答案
尝试用以下命令替换当前的滑块功能:
try replacing your current slider function with this:
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
访问输入值。 - 在
renderUI
函数内部移动date_of_month
的计算对input $ interval
的变化有反应。
- Use
input$interval
rather thaninterval
to access the input value. - Move the calculation of
date_of_month
inside therenderUI
function so that it is reactive to changes ininput$interval
.
这篇关于R带有renderUI的闪亮动画滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!