How to get the output from multiple action buttons? Please help me! I am sending you my codes.

library(shiny)

ui <- fluidPage(
titlePanel("MY APP"),
numericInput("o","No. of overs completed:",min=0,max=19,value=0),
helpText("Input values 5, 10 or 15"),
numericInput("w","No. of wickets lost:",min=0,max=9,value=0),
helpText("Input range from 0 to 9"),
numericInput("r","Runs scored:",min=0,max=300,value=0),
submitButton("Compute", icon("refresh")),
helpText("Click here to get the final score"),
verbatimTextOutput("score", placeholder = TRUE),
actionButton("ci90","90% CI"),
actionButton("ci95","95% CI"),
actionButton("ci99","99% CI"),
br(),
br(),
textOutput("lo"),
br(),
textOutput("up")
)

server = function (input, output, session){

v = reactiveValues(s=0,e=0,l90=0,l95=0,l99=0,u90=0,u95=0,u99=0)

v$s = reactive({
if(is.na(input$o)){
return(NULL)}
if(is.na(input$w)){
return(NULL)}
if(is.na(input$r)){
return(NULL)}

if(input$o==5){
  s=153.757-8.79*input$w+input$r*0.704
}
else if(input$o==10){
  s=101.831-2.29*input$w+input$r*0.974
}
else if(input$o==15){
  s=60.207-2.513*input$w+input$r*1.009
}
else {
  return(NULL)
}
return(round(s,digits = 0))

})

v$e = reactive({

if(is.na(input$o)){
  return(NULL)}
if(is.na(input$w)){
  return(NULL)}
if(is.na(input$r)){
  return(NULL)}

if(input$o==5){
  e=(568.46+((input$r-39.66)^2)*0.065+((input$w-1)^2)*7.465+(input$r-39.66)*(input$w-1)*0.223)^0.5
}
else if(input$o==10){
  e=(466.45+((input$r-77.65)^2)*0.026+((input$w-2)^2)*3.773+(input$r-77.65)*(input$w-2)*0.142)^0.5
}

else if(input$o==15){
  e=(208.984+((input$r-120.42)^2)*0.007+((input$w-3.51)^2)*1.282+(input$r-120.42)*(input$w-3.51)*0.048)^0.5
}

else {
  return(NULL)
}
return(round(e,digits = 0))

})

output$score = renderText({

if(is.null(v$s())){
  return(NULL)
}
else {
  return(v$s())
}

})

observeEvent(input$ci90,{
v$l90=v(s)-1.68*v$e()
})

observeEvent(input$ci95,{
v$l95=v$s()-1.96*v$e()
})

observeEvent(input$ci99,{
v$l99=v$s()-2.62*v$e()
})

observeEvent(input$ci90,{
v$u90=v$s()+1.68*v$e()
})

observeEvent(input$ci95,{
v$u95=v$s()+1.96*v$e()
})

observeEvent(input$ci99,{
v$u99=v$s()+2.62*v$e()
})

output$lo=renderText({
if(input$ci90)
print(v$l90())
else if(input$ci95)
print(v$l95())
else if(input$ci99)
print(v$l99())
})

output$up=renderText({
if(input$ci90)
print(v$u90())
else if(input$ci95)
print(v$u95())
else if(input$ci99)
print(v$u99())
})

}

Please format your code properly. This is a mess. Use triple backticks ``` before code blocks and fix the identation.

You can't use if() with a reactive object like input$o. input$o is numeric in your case and has a value between 0 and 19. if(input$o) doesn't make sense. Don't worry about checking whether the values are NA or NULL, until you get a problem. Shiny usually handles that automatically.

v$s = reactive() is not how you set reactive values in shiny, You have to do it within a reactive context.

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

Thank you so much for your response. I am attaching my server codes again. Please help me to execute the output using action button. I am new and trying to learn R shiny.

server = function (input, output, session){
  
v = reactiveValues(s=0,e=0)
  
    v$s = reactive({

          if(input$o==5){
            s=153.757-8.79*input$w+input$r*0.704
          }
          else if(input$o==10){
            s=101.831-2.29*input$w+input$r*0.974
          }
          else if(input$o==15){
            s=60.207-2.513*input$w+input$r*1.009
          }
          else {
            return(NULL)
          }
          return(round(s,digits = 0))
      })  
  
    v$e = reactive({
  
          if(input$o==5){
            e=(568.46+((input$r-39.66)^2)*0.065+((input$w-1)^2)*7.465+(input$r-39.66)*(input$w-1)*0.223)^0.5
          }
          else if(input$o==10){
            e=(466.45+((input$r-77.65)^2)*0.026+((input$w-2)^2)*3.773+(input$r-77.65)*(input$w-2)*0.142)^0.5
          }
          else if(input$o==15){
            e=(208.984+((input$r-120.42)^2)*0.007+((input$w-3.51)^2)*1.282+(input$r-120.42)*(input$w-3.51)*0.048)^0.5
          }
          else {
            return(NULL)
          }
          return(round(e,digits = 0))
      })

   output$score = renderText({

                      if(is.null(v$s())){
                        return(NULL)
                      }
                      else {
                        return(v$s())
                      }
                })

   observeEvent(input$ci90,{
      
        v$l90=v(s)-1.68*v$e()
    })
  
  observeEvent(input$ci95,{
    
        v$l95=v$s()-1.96*v$e()
    })
  
  observeEvent(input$ci99,{
    
        v$l99=v$s()-2.62*v$e()
    })
  
  observeEvent(input$ci90,{
    
        v$u90=v$s()+1.68*v$e()
    })
  
  observeEvent(input$ci95,{
    
        v$u95=v$s()+1.96*v$e()
    })
  
  observeEvent(input$ci99,{
    
        v$u99=v$s()+2.62*v$e()
    })

output$lo=renderText({
    
              if(input$ci90)
                  print(v$l90())
              else if(input$ci95)
                  print(v$l95())
              else if(input$ci99)
                  print(v$l99())
            })
  
  output$up=renderText({
    
              if(input$ci90)
                  print(v$u90())
              else if(input$ci95)
                  print(v$u95())
              else if(input$ci99)
                  print(v$u99())
            })
  
  
}