R Shiny animated slider with renderUI

≡放荡痞女 提交于 2019-12-13 02:19:29

问题


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.

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

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

回答1:


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))
})
  1. Use input$interval rather than interval to access the input value.
  2. Move the calculation of date_of_month inside the renderUI function so that it is reactive to changes in input$interval.


来源:https://stackoverflow.com/questions/28522812/r-shiny-animated-slider-with-renderui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!