Unable to generate output using IF statement in shiny

Hi, Please assist to review the below code, I have written my code I am unable to generate desired output in the "Body Chasis" tab. I have used if statement but not getting the output as i change the number.

UI

library(shiny)
library(shinydashboard)

shinyUI(fluidPage(

titlePanel("Zero Based Costing Model"),

sidebarLayout(

sidebarPanel(("Enter client details"),

conditionalPanel(condition = "input.tabselect == 1",

             textInput("client_name", "Enter the Client Name", value = " "),

             selectInput("route_IO", "Enter the route whether it is Inbound or Outound", 
             choices = c("Inbound","Outbound"), selected = NULL, multiple = FALSE),

             textInput("route_start", "Enter the route start point", value = ""),

             textInput("route_end", "Enter the route end point ", value = ""),

             radioButtons("GST_Mechanism", "Enter the mechanism of GST",
             choices = c("RCM","FCM"), selected = NULL ),style = {"color:green;font-size: 20px"}),


conditionalPanel(condition = "input.tabselect==2",
  
              textInput("model","Enter the Model of the Vehicle",value = " "),               
                 
              numericInput("n","Enter the distance between start location and end location in KMs", value = 1, min = 1),


              selectInput("Road type", "Enter the Road or Terrain Type", 
              choices = c("Highway","Non-Highway","Hilly","Non Tar","Type B","Type C"),
              selected = NULL, multiple = FALSE),
 
              radioButtons("vehicle_type", "Enter the vehicle type", 
              choices = c("Market","Dedicated"), selected = NULL ),
 
              numericInput("fuel price","Enter the Fuel Price, Inr/Litre", value = 1, min = 1),
              
              numericInput("fuel eff with load","Enter the Fuel Price with load, Inr/Litre", value = 1, min = 1),     
 
              numericInput("fuel eff without load","Enter the Fuel Price with load, Inr/Litre", value = 1, min = 1),
              
              numericInput("trip efficiency","Enter the trip efficiency in percentage", 
              value = 1, min = 1, max = 100, step = 0.5),

              numericInput("run", "Enter run", 1),
 
              sliderInput("profir_margin", "Enter the profit margin for transporter", 
              min = 0, max = 30, step = 0.5, value = " ")),
 

conditionalPanel(condition = "input.tabselect == 3",

                 numericInput("driver","Enter the number of Drivers Involved for the trip",1),
                 numericInput("Driver_sal","Enter the salary of all the Drivers Involved for the trip",1),
                 numericInput("cleaner","Enter the number of Cleaners Involved for the trip",0),
                 numericInput("Cleaner_sal","Enter the salary of all the Cleaners Involved for the trip",0),
                 numericInput("Bhatta","Enter the daily bhatta for driver + cleaner as per 25 day working ",1),
                 numericInput("Admin","Number of  Admin Staff ",1),
                 numericInput("Admin_route","Number of Routes Handled by Admin Staff ",1),
                 numericInput("Admin_sal","Enter the salary of the Admin Staff",1),
                 numericInput("Admin_sal","Enter the salary of the Admin Staff",1),
                 numericInput("Tar","Enter the cost for Tarpaulin",1),
                 numericInput("Bank","Enter the bank Guarantee Amount (INR/Month): ",1),
                 numericInput("Gps","Enter the GPS installation Cost (One Time): ",0),
                 numericInput("Gps_trip","GPS Trip Charge ",0)),


conditionalPanel(condition = "input.tabselect == 4",

                 numericInput("Amc","Enter the AMC cost (Inclusive of GST) ",1),
                 numericInput("Ann_run","Enter annual running of the vehicle",1),
                 numericInput("warai","Enter the Loading/Unloading/Warai charges",1),
                 numericInput("Cleaner_sal","Enter the salary of all the Cleaners Involved for the trip",0),
                 numericInput("Toll","Enter the toll charge of the trip (One Side) ",1),
                 numericInput("LR","Enter the LR charges ",1),
                 numericInput("RTO","Enter the RTO Expense ",1),
                 numericInput("Gunda","Enter the Gunda Tax",1),
                 numericInput("Over_height","Enter the over height challan cost",1)),

conditionalPanel(condition = "input.tabselect == 5",

                 numericInput("front tyres","Enter the number of front tyres",2),
                 numericInput("rear tyres","Enter the number of rear tyres",4),
                 numericInput("tyre life","Enter the Life of tyre in Km",60000),
                 numericInput("front tyre cost","Enter the front tyre cost per unit",16000),
                 numericInput("rear tyre cost","Enter the rear tyre cost per unit",16000),
                 numericInput("LR","Enter the LR charges ",1),
                 numericInput("RTO","Enter the RTO Expense ",1),
                 numericInput("Gunda","Enter the Gunda Tax",1),
                 numericInput("Over_height","Enter the over height challan cost",1)),


conditionalPanel(condition = "input.tabselect == 6",

                 numericInput("License","Enter the one time License Cost",1000),
                 numericInput("Reg_char","Enter the one time registration charger",25000),
                 numericInput("Nat_permit","Enter the charges for national permit (INR/Yr)",20000),
                 numericInput("Road_tax","Enter the Road Tax amount (INR/Yr)",16000),
                 numericInput("Fitness_cert","Enter the charges for fitness certificate",2500),
                 numericInput("Puc","Enter the charges for PUC ",600),
                 numericInput("RTO","Enter the RTO Expense ",1),
                 helpText("Insurance Cost"),
                 numericInput("IDV","Enter the insured declaration value in percentage",90),
                 numericInput("Insurance_cost","insurance cost",3)),


conditionalPanel(condition = "input.tabselect == 7",
                 

                 numericInput("Chasis","Enter the original cost of chasis and cabin",100000),

                 numericInput("Reg_char","Enter the number of years after chasis and cabin making",0))),

submitButton("Check the details before submitting")),

mainPanel(
  
          tabsetPanel(type = "pills",
                      
                      tabPanel("Client & Route Details", value =1, 
                                textOutput("Myclient_name"), textOutput("Myroute_IO"), 
                               textOutput("Myroute_start"), textOutput("Myroute_end"),  textOutput("MyGST"), 
                               style = {"color:black;font-size: 20px;line-height: 2.92857143"}),

                      tabPanel("Trip Detail",value =2, textOutput("dist"),textOutput("Mymodel")),
                      tabPanel("Fixed Operating Cost",value =3),
                      tabPanel("Maintenance Cost",value =4),
                      tabPanel("Variable Cost",value =5),
                      tabPanel("Regulatory and Insurance Cost",value =6),
                      tabPanel("Body Chasis", value = 7, textOutput("MyChasis"), textOutput("MyReg_char1")),
                       
                      id = "tabselect"
                      
                      ))

)))

SERVER
library(shiny)
library(shinydashboard)

shinyServer(function(input, output){

         output$Myclient_name <- renderText({
           
           paste("Please Enter Client's Name:", input$client_name)
           
         })
         
        output$Myroute_IO <-  renderText({
       
          paste("Route Selected Is As : ", input$route_IO)
       
          })
       
        output$Myroute_start <-  renderText({
       
          paste("Start point of the client entered: ", input$route_start)
       
          })
       
        output$Myroute_end <-  renderText({
       
          paste("End point of the client entered: ", input$route_end)
       
       
          })
       
        output$Myvehicle_type <-  renderText({
       
          paste(" Vehicle used is Market or Dedicated: ",input$vehicle_type)
       
       
          })
       
        output$Myprofir_margin <- renderText({
       
       
          paste("Profit Margin for trip to be given to transporter: ",input$profir_margin)
       
       
          })
       
        output$MyGST <- renderText({
       
       
          paste("GST mechanism selected by the client is: ",input$GST_Mechanism)
       
                         })
       
        output$dist <- renderText({
       
       
         paste("The Distance Entered is : ", input$n)
       
        })
       
       
        output$Mymodel <- renderText({
       
       
          paste("The vehicle model Entered is : ", input$model)
       
        })
        
        
        output$MyChasis <- renderText({
          
          paste("Original Cost of the Chasis is :", input$Chasis)
          
        })
        
        
        output$MyReg_char1 <- renderText({
          
          input$Reg_char
          
          if (input$Reg_char == 1 ){
            
            paste("The current cost of the vehicle with respect to number of years: ", 
                  input$Chasis * 0.9500)
            
          } else{
            
            paste("Not in Condition")
            
          }
          
          
        })
    })

I think it might be a problem for you that you declare two numeric inputs with the same inputId of Reg_char

2 Likes

Even if i remove input$Reg_char before the line
if (input$Reg_char == 1 ){
I am still unable to execute the if statement with the given condition.

Hi,

It worked, i changed the name Reg_char. Thank you very much.

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