vendredi 6 août 2021

Multiple "if" condition for R-Shiny Calculator App

I want to create an R-shiny application that calculates creatinine clearance. According to the formula below, the calculation necessitates many "if" conditions:

enter image description here

In addition, I'd like to show the results of the dose adjustment depending on the creatinine clearance data.

The following is the code I'm attempting to create. Still, I'm having difficulty displaying the final results table that includes the creatinine clearance calculations (based on gender and serum creatinine conditions) and how to show antibiotic dose adjustments based on creatinine clearance results.


library(shiny)

# USER INTERFACE
ui <- fluidPage(
                        # Give the page a title
                        titlePanel("Kalkulator CCT"),
                        helpText("Aplikasi ini menghitung creatinine clearance berdasarkan rumus CKD-EPI dan ditambahkan dengan penyesuaian dosis antibiotik "),
                        # left input 
                        sidebarPanel(
                                     
                                     
                                     radioButtons(inputId = "sex", label = "sex", choices = c("Male", "female"), inline = TRUE),
                                     
                                     
                                     numericInput(inputId = "age", label = "Age (years)", value = 18, min = 0, max = 100, width=validateCssUnit("50%")),
                                     uiOutput("age"),                         
                                     numericInput(inputId = "cre", label = "Serum creatinine (mg/dL", value = 0.89, min = 0, max = 10, width=validateCssUnit("50%")),
                                     uiOutput("cre"),
                                     checkboxGroupInput("ab", "Type of antibiotics:",
                                                        c("Meropenem" = "mer",
                                                          "Levofloxacin" = "lev"
                                                         )),
                                     helpText("choose the antibiotics")
                                     
                                     ),
                        # right outputs
                        mainPanel(br(),
                                  # h3("Results"),
                                  br(),
                                  dataTableOutput("results"), width=6 ))
    )
)




# SERVER function

server <- function(input, output, session) {
    
    
    # Evaluate Design Effect for selected options, and output table with values
    results.data.table <- reactive({
        
        if(input$sex=="Male")
        {
            m1 <- input$cre >= 0.9
            m2 <- imput&cre < 0.9
            CCT<-round(141*(input$cre/m1)^-0.411*(0.993^input$umur))
            CCT<-round(141*(input$cre/m2)^-1.209*(0.993^input$umur))
            mer1 <- #if checkboxGroupInput is meropenem and CCT >50 show text "0.5-1 g IV q8hr" in finalresults antibiotics
            mer2 <- #if  checkboxGroupInput is meropenem and CCT 26-50 show "0.5-1 g IV q12hr"    in finalresults antibiotics
            mer3 <- #if  checkboxGroupInput is meropenem and CCT 10-25 show "0.25-0.5 g IV q12hr"    in finalresults antibiotics
            mer4 <- #if  checkboxGroupInput is meropenem and CCT <25 show "0.25-0.5 g IV q24hr"    in finalresults antibiotics
            lev1 <- #if  checkboxGroupInput is levofloxacin and CCT 20-49 show "750 mg initially, then 500 mg every other day"    in finalresults antibiotics 
            lev2 <- #if  checkboxGroupInput is levofloxacin and CCT 10-19 show "500 mg initially, then 250 mg every other day"    in finalresults antibiotics 
                
                
        }
        
        else if (input$sex == "Female")
        {
            f1 <- input$cre >= 0.7
            f2 <- input$cre < 0.7
            CCT<-round(144*(input$cre/f1)^-0.329*(0.993^input$umur))
            CCT<-round(144*(input$cre/f2)^-1.209*(0.993^input$umur))
            mer2 <- #if  checkboxGroupInput is meropenem and CCT 26-50 show "0.5-1 g IV q12hr"    in finalresults antibiotics
            mer3 <- #if  checkboxGroupInput is meropenem and CCT 10-25 show "0.25-0.5 g IV q12hr"    in finalresults antibiotics
            mer4 <- #if  checkboxGroupInput is meropenem and CCT <25 show "0.25-0.5 g IV q24hr"    in finalresults antibiotics
            lev1 <- #if  checkboxGroupInput is levofloxacin and CCT 20-49 show "750 mg initially, then 500 mg every other day"    in finalresults antibiotics 
            lev2 <- #if  checkboxGroupInput is levofloxacin and CCT 10-19 show "500 mg initially, then 250 mg every other day"    in finalresults antibiotics 
                
        }
        
        row.names<-c("CCT")
        
        finalresult<-data.frame("Result"=row.names, "Value"= CCT, "Antibiotics" = AB)
        
    })
    
    
    # Output data table results without any data table options (page no., row number, etc..)
    output$results <- renderDataTable({results.data.table()}, options = list(lengthChange= F, paging = F, searching = F, ordering= F, info=F))
    
    
}

shinyApp(ui = ui, server = server)

Your assistance is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire