R中的if else语句可用于计算

时间:2020-01-31 13:02:03

标签: r shiny

我已经开始练习R Shiny,请在我的代码下面找到我要进行计算的地方。由于无法生成,请协助获取输出。

UI

图书馆(闪亮) 库(shinydashboard)

shinyUI(fluidPage(

titlePanel(“基于零成本的成本核算模型”),

sidebarLayout(

sidebarPanel((“输入客户详细信息”),

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(“提交前检查详细信息”)), #

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**

图书馆(闪亮) 库(shinydashboard)

shinyServer(函数(输入,输出){

         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({

          if (as.numeric(input$Reg_char == 1)  ){

            paste("The current cost of the vehicle with respect to number of years: ", 
                  as.numeric(input$Chasis * 0.9500))

          } else{

            paste("Not in Condition")

          }


        })

1 个答案:

答案 0 :(得分:0)

有关工作模型,请参见下文。我建议您看一些有关制作闪亮的仪表板的教程(https://shiny.rstudio.com/reference/shiny/latest/fluidPage.html),因为上面的代码在错误的位置放置了参数,并且您错过了实际上称为仪表板的地方... shinyApp()

library(shiny)
library(shinydashboard)

ui <- fluidPage(

  titlePanel("Zero Based Costing Model"),

  sidebarLayout(

    sidebarPanel(
      "Enter client details",
      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)
    ),
    mainPanel(
      tabsetPanel(type = "pills",
                  tabPanel("Body Chasis", value = 7, textOutput("MyChasis"), textOutput("MyReg_char")),
                  id = "tabselect"
      )
    )
  )
)

server <- function(input, output){


  output$MyChasis <- renderText({

    paste("Original Cost of the Chasis is :", input$Chasis)

  })


  output$MyReg_char <- renderText({

    if (as.numeric(input$Reg_char == 1)  ){

      paste("The current cost of the vehicle with respect to number of years: ", as.numeric(input$Chasis * 0.9500))

    } else{

      paste("Not in Condition")

    }


  })

}

shinyApp(ui, server)