Using text input to calculate value for another text input in shiny app

I would like to give the option to either input a percentage or a value. When the user inputs one of the two, I would like the other to autofill.

So for the code:

textInput(DownDollars, "Downpayment (Dollars)", value = "", width = NULL, placeholder = NULL),

textInput(DownPercent, "Downpayment (Percent)", value = "", width = NULL, placeholder = NULL)

Is there a way to use the output of these inputs to replace the value = option?

UPDATE: Here is the code that doesn't work for using another input for the reference value:

ui <- fluidPage(
  numericInput("HomePrice", "Home Price", value = ""),
  
  numericInput("DownPaymentDollars", "Down Payment (Dollars)", value = "", width = NULL),
  
  numericInput("DownPaymentPercent", "Down Payment (Percent)", value = "", width = NULL)
)

server = function(input, output, session){
  
  #referenceValue <- 254
  
  observeEvent(input$DownDollars, {
    updateNumericInput(session, "DownPaymentPercent", value = input$DownDollars * 100 / input$HomePrice)
  })
  
  observeEvent(input$DownPercent, {
    updateNumericInput(session, "DownPaymentDollars", value = input$DownPercent * input$HomePrice / 100)
  })
  
}

shinyApp(ui, server)


from Recent Questions - Stack Overflow https://ift.tt/3gBOCZo
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)