Having Trouble with Shiny Output

I am having trouble getting any output to appear. All I see is the error
"Warning: Error in /: non-numeric argument to binary operator
[No stack trace available]"

Thank you for any help you can give me.

ui<-fluidPage(
  titlePanel("Economic Return for Nitrogen Application"),
  sidebarLayout(
    sidebarPanel(
      selectInput("PercentNitrogenInput", "% Nitrogen", choices=c(".46", ".82")),
      numericInput("Fertilizer_CostInput", "Fertilizer Cost Per Ton", value=0, min=0),
      numericInput("Selling_PriceInput", "Price Per Bushel", value=0, min=0)),
    mainPanel(
      textOutput("Breakeven_Selling_PointOutput")
    )
  )
)

server<-function(input,output){
  output$Breakeven_Selling_PointOutput<- renderPrint({
    ((((input$Fertilizer_CostInput/2000)/input$PercentNitrogenInput)/input$Selling_PriceInput)-0.7199)/(2*-0.0019)
  })
}
   
shinyApp(ui = ui, server = server)```

Hi @Aggie4. The error come from the input$PercentNitrogenInput is a character, so you cannot use it in calculation. Change to to numeric by as.numeric will do.

ui<-fluidPage(
  titlePanel("Economic Return for Nitrogen Application"),
  sidebarLayout(
    sidebarPanel(
      selectInput("PercentNitrogenInput", "% Nitrogen", choices=c(".46", ".82")),
      numericInput("Fertilizer_CostInput", "Fertilizer Cost Per Ton", value=0, min=0),
      numericInput("Selling_PriceInput", "Price Per Bushel", value=0, min=0)),
    mainPanel(
      textOutput("Breakeven_Selling_PointOutput")
    )
  )
)

server<-function(input,output){
  output$Breakeven_Selling_PointOutput<- renderPrint({
    ((((input$Fertilizer_CostInput/2000)/as.numeric(input$PercentNitrogenInput))/input$Selling_PriceInput)-0.7199)/(2*-0.0019)
  })
}

shinyApp(ui = ui, server = server)
1 Like

Thank you very much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.