【问题标题】:Interactive / Reactive change of min / max values of sliderInput滑动输入的最小值/最大值的交互式/反应性变化
【发布时间】:2013-09-09 14:29:07
【问题描述】:

我找到了some information,了解如何使用siderbarPanel 中的反应式表达式更改sliderInputvalue。但不是value,我想用numericInput 更改滑块的minmax。在server.Rthis 脚本中,它说只有labelvalue 可以更改滑块。是否有任何其他可能性可以使用响应式表达式更改 sliderInput 的最小/最大值?

这是一个例子:

ui.R:

shinyUI(pageWithSidebar(
  
  #Sidebar with controls to select the variable to plot
  sidebarPanel(
   
  #Numeric Inputs
    numericInput("min_val", "Enter Minimum Value", 1993),
    
    numericInput("max_val", "Enter Maximum Value", 2013),

  #Slider 
    sliderInput("inSlider", "Slider", 
                min=1993, max=2013, value=2000),

# Now I would like to change min and max from sliderInput
# by changing the numericInput.

  mainPanel()
))

服务器.R:

library(shiny)

shinyServer(function(input, output, session) {

  reactive({
    x<-input$min_val
    y<-input$max_val
    updateSliderInput(session, "inSlider", min=x, max=y, value=x)
  })
}

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    我认为这最好通过renderUI()uiOutput() 使用闪亮的动态UI 功能来实现。试试下面的例子:

    ui.R

    library(shiny)
    
    shinyUI(pageWithSidebar(
      headerPanel("Test Shiny App"),
    
      sidebarPanel(
        #Numeric Inputs
        numericInput("min_val", "Enter Minimum Value", 1993),
        numericInput("max_val", "Enter Maximum Value", 2013),
        #display dynamic UI
        uiOutput("slider")
      ),
    
      mainPanel()
    ))
    

    服务器.R

    library(shiny)
    
    shinyServer(function(input, output, session) {
    
      #make dynamic slider
      output$slider <- renderUI({
        sliderInput("inSlider", "Slider", min=input$min_val, max=input$max_val, value=2000)
      })
    
    })
    

    【讨论】:

    • 感谢@David,滑块工作!但是我无法从滑块中获取输出值。我试过input$slider,但似乎slider 没有返回任何值。有什么想法吗?
    • 刚刚意识到我必须使用input$inSlider 。抱歉打扰了。
    • 我经常这样写 uiOutput("outputSlider") 和 sliderInput("inputSlider", etc) 以避免混淆...
    • 我认为现在已经贬值了。
    猜你喜欢
    • 2015-10-10
    • 2015-04-10
    • 2016-11-25
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多