I am trying to create a shiny app that calculates drug rates based on dosages and mass for a veterinary clinic and then the tech can print the resulting table for a care sheet. I've seen where selectInput can be used to load a dataset and display it as a table, but I need to create the rates in the tables based upon the mass of the animal and drug concentration. For example, a drug may have a dosage of 1,2,3,4, or 5 mcg/kg/hr which can hopefully be loaded based upon the drug selected via selectInput, but I need the rate to be calculated by a formula (in this case (mass * dose)/concentration). This is further complicated by the fact that each drug has different dosages, so that also needs to be reactive based upon the selectInput.
What I have so far is below, but I haven't been able to get any tables to be produced that are responding to the data from the shiny app.
library(shiny)
drug.selections <- c("Fentanyl", "Ketamine", "Lidocaine", "Midazolam", "Metoclopramide", "Norepinephrine", "Dobutamine",
"Dopamine", "Epinephrine", "Phenylephrine", "Propofol", "Dexmedetomidine 0.1 mg/dl", "Dexmedetomidine 0.5 mg/dl", "Diltiazem", "Furosemide", "Butorphanol",
"Hydromorphine", "Morphine", "Methadone", "ACA", "Magnesium", "Alfaxalone")
drug.selections <- sort(drug.selections)
ui <- fluidPage(
headerPanel("Continuous Rate Infusion"
),
sidebarLayout(
sidebarPanel(
textInput("name", "Pet Name"),
numericInput("mass", "Pet Weight (kg)", value = 0, min =0, max = 200),
selectInput("drug", "Drug", drug.selections),
numericInput("concentration", "Concentration", value = 0, min = 0, max = 500),
numericInput("time", "How many hours needed", value = 0, min = 0, max = 40),
checkboxInput("dilute", "Dilute?", value = FALSE)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Dose", tableOutput("dose")),
tabPanel("Diluted Dose", tableOutput("ddose")),
tabPanel("Dilution Recipe", tableOutput("recipe")),
tabPanel("Summary", textOutput("summary")),
textOutput("name"),
textOutput("mass"),
textOutput("drug")
)
)
)
)
server <- function(input, output, session) {
mass <- reactive({
get(input$mass, inherits = FALSE)
})
output$summary <- renderText({
paste (input$name, "weighs", input$mass, "kg and is on", input$concentration, "of", input$drug)
})
output$dose <- renderTable({
dose
})
output$ddose <- renderTable({
ddose
})
output$recipe <- renderTable({
recipe
})
}
shinyApp(ui, server)
I would like to get the "Dose" tab to produce a table of the dose and rate. Pretty sure I can do something similar for the other tabs. Can someone point me in the right direction?