R 根据值的总和更新三个不同的输入

R 根据值的总和更新三个不同的输入,r,shiny,reactive,R,Shiny,Reactive,我的ShinyApp中有四个用户输入: 第一个输入(总价)始终存在 rrsp的可选输入,允许用户输入值(最大35000) fthbi的可选输入,允许用户选择高达10%的值 允许用户输入值的现金的其他付款 在我的代码中,total_input和cash是numericInput,rrsp和fthbi是checkBoxInput+conditionalPanel 总价独立于其他三项。但是,其他三项合计不得超过总价的20%,即rrsp+fthbi*总价+现金Aou在使用update*功能方面是正确的。

我的ShinyApp中有四个用户输入:

  • 第一个输入(
    总价
    )始终存在
  • rrsp
    的可选输入,允许用户输入值(最大35000)
  • fthbi
    的可选输入,允许用户选择高达10%的值
  • 允许用户输入值的
    现金的其他付款
  • 在我的代码中,
    total_input
    cash
    numericInput
    rrsp
    fthbi
    checkBoxInput
    +
    conditionalPanel


    总价
    独立于其他三项。但是,其他三项合计不得超过
    总价的20%,即
    rrsp+fthbi*总价+现金Aou在使用
    update*
    功能方面是正确的。我不打算实现完整的逻辑,但下面的代码片段应该为您指明了正确的方向:

    # Basic usage
    library("shiny")
    library(shinyWidgets)
    
    ui <- fluidPage(
      titlePanel(
        'My App'
      ), 
      sidebarLayout(
        sidebarPanel = sidebarPanel(
          numericInput(
            inputId = 'total_price', 
            label = 'Total Price', 
            value = 200000,
            min = 200000
          ),
          
          # Use RRSP for down-payment
          checkboxInput(
            inputId = 'use_rrsp', 
            label = 'Use RRSP?', 
            value = F
          ), 
          
          # If using RRSP, select amount to use
          conditionalPanel(
            condition = "input.use_rrsp == true",
            numericInput(
              inputId = 'rrsp', label = 'RRSP Amount?',value = 25000, min = 0, 35000
            )
          ),
          
          # Use first time home buyer incentive?
          checkboxInput(
            inputId = 'use_fthbi', 
            label = 'Use FTHBI?', 
            value = F
          ), 
          
          # If using FTHBI, select % to use
          conditionalPanel(
            condition = "input.use_fthbi == true",
            sliderInput(
              inputId = 'fthbi', label = 'FTHBI Percent',
              step = 1, min = 0, max = 10, value = 0, post = '%'  
            )
          ),
          
          # Cash Downpayment
          numericInput(
            inputId = 'cash', label = 'Cash Payment', value = 0, min = 0, max = 40000
          )
        ), 
        mainPanel = mainPanel(
          textOutput('main_text')
        )
      )
    )
    
    server <- function(input, output, session){
      output$main_text <- renderText({
        sprintf('Sample Text')
      })
      
      
      observe({
        # check that the input exists, is not null etc. check ?req()
        req(input$cash)
        if(input$cash > 0)
          updateSliderInput(session = session,
                            inputId = 'fthbi',
                            max = round(40000 / input$cash))
      })
    }
    
    shinyApp(ui, server)
    
    #基本用法
    图书馆(“闪亮”)
    图书馆(shinyWidgets)
    
    ui总是
    rrsp+fthbi*总价+现金@starja我添加了一些逻辑,希望能澄清问题。
    
    # Basic usage
    library("shiny")
    library(shinyWidgets)
    
    ui <- fluidPage(
      titlePanel(
        'My App'
      ), 
      sidebarLayout(
        sidebarPanel = sidebarPanel(
          numericInput(
            inputId = 'total_price', 
            label = 'Total Price', 
            value = 200000,
            min = 200000
          ),
          
          # Use RRSP for down-payment
          checkboxInput(
            inputId = 'use_rrsp', 
            label = 'Use RRSP?', 
            value = F
          ), 
          
          # If using RRSP, select amount to use
          conditionalPanel(
            condition = "input.use_rrsp == true",
            numericInput(
              inputId = 'rrsp', label = 'RRSP Amount?',value = 25000, min = 0, 35000
            )
          ),
          
          # Use first time home buyer incentive?
          checkboxInput(
            inputId = 'use_fthbi', 
            label = 'Use FTHBI?', 
            value = F
          ), 
          
          # If using FTHBI, select % to use
          conditionalPanel(
            condition = "input.use_fthbi == true",
            sliderInput(
              inputId = 'fthbi', label = 'FTHBI Percent',
              step = 1, min = 0, max = 10, value = 0, post = '%'  
            )
          ),
          
          # Cash Downpayment
          numericInput(
            inputId = 'cash', label = 'Cash Payment', value = 0, min = 0, max = 40000
          )
        ), 
        mainPanel = mainPanel(
          textOutput('main_text')
        )
      )
    )
    
    server <- function(input, output, session){
      output$main_text <- renderText({
        sprintf('Sample Text')
      })
      
      
      observe({
        # check that the input exists, is not null etc. check ?req()
        req(input$cash)
        if(input$cash > 0)
          updateSliderInput(session = session,
                            inputId = 'fthbi',
                            max = round(40000 / input$cash))
      })
    }
    
    shinyApp(ui, server)