R Shiny 带有 renderUI 的动画滑块 [英] R Shiny animated slider with renderUI

查看:27
本文介绍了R Shiny 带有 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.

但是当我将动画选项放在渲染UI 中时,它无法正常工作.在我的 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))
})

  1. 使用 input$interval 而不是 interval 来访问输入值.
  2. renderUI 函数中移动 date_of_month 的计算,以便它对 input$interval 的变化作出反应.
  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.

这篇关于R Shiny 带有 renderUI 的动画滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆