I am trying to build a shiny dashboard where i have to use an if statement to determine how a variable should be treated. in this case, the if statement assigns a multiple (either 1 or 0) which is then multiplied by multiple variables later in the code. I am unable to get an IF statement to work outside a renderUI function for some reason. I have tried to make it a reactive function but that did not work either.
server <- function(input, output, session) {
LinerCost <- reactive ({ input$LLDPE_Liner/100 * DirectRM_Cost$Rs_KG[15] +
input$Metallocene/100 * DirectRM_Cost$Rs_KG[16] +
input$TPT/100 * DirectRM_Cost$Rs_KG[17] +
input$UV_Liner/100 * DirectRM_Cost$Rs_KG[18] +
input$CMB_Liner/100 * DirectRM_Cost$Rs_KG[19] +
input$Other_Additive_Liner/100 * DirectRM_Cost$Rs_KG[20]})
reactive({if (input$lamination == "lam_yes") {
lam_rm_multiple = 1} else {
lam_rm_multiple = 0
}})
reactive({if (input$liner == "liner_yes") {
liner_rm_multiple = 1} else {
liner_rm_multiple = 0
}})
LamCost <- reactive({ LamCost * lam_rm_multiple })
LinerCost <- reactive ({LinerCost * liner_rm_multiple})
CombinedWeight <- reactive ({as.numeric(input$final_unlam_weight) + as.numeric(input$final_lam_weight) * lam_rm_multiple +
as.numeric(input$final_liner_weight) * liner_rm_multiple})
RMcost <- reactive({((as.numeric(input$final_unlam_weight) / CombinedWeight()) * UnLamCost()) +
((as.numeric(input$final_lam_weight) / CombinedWeight()) * LamCost()) +
((as.numeric(input$final_liner_weight) / CombinedWeight()) * LinerCost()) })
}
shinyApp(ui, server)
Here, I want the lam_rm_multiple to be assigned a value of either 0 or 1 and it is then multiplied to variables and force them to 0 as required. Currently, i get an error in shiny saying - Warning: Error in : object 'lam_rm_multiple' not found
Aucun commentaire:
Enregistrer un commentaire