library(shiny) library(bslib) library(mrgsolve) library(dplyr) library(ggplot2) model_code <- ' $PARAM @annotated CL : 6.3 : Clearance (L/h) V : 105 : Volume of distribution (L) KA : 1.25 : Absorption rate constant (1/h) F1 : 0.65 : Bioavailability WT : 70 : Body weight (kg) HEPF : 1.0 : Hepatic function (fraction of normal) $CMT @annotated DEPOT : Oral depot (mg) CENT : Central (mg) $MAIN double CLi = CL * (WT/70.0) * HEPF; double Vi = V * (WT/70.0); F_DEPOT = F1; $ODE dxdt_DEPOT = -KA * DEPOT; dxdt_CENT = KA * DEPOT - (CLi/Vi) * CENT; $TABLE double CP = (CENT / Vi) * 1000; $CAPTURE CP ' mod <- mcode("doxazosin", model_code) app_theme <- bs_theme( version = 5, bootswatch = "flatly", primary = "#8b5cf6" ) |> bs_add_rules(" .metric-card { background: #f8f9fa; border-radius: 8px; padding: 15px; margin: 5px; text-align: center; border: 1px solid #dee2e6; } .metric-value { font-size: 24px; font-weight: bold; color: #2c3e50; } .metric-label { font-size: 12px; color: #7f8c8d; } .metric-success .metric-value { color: #10b981; } .metric-warning .metric-value { color: #f59e0b; } .metric-primary .metric-value { color: #8b5cf6; } .metric-info .metric-value { color: #0dcaf0; } .ref-box { background: #f0f4ff; border-left: 4px solid #8b5cf6; padding: 12px 16px; border-radius: 4px; margin-top: 10px; font-size: 13px; } .ref-box a { color: #8b5cf6; } ") ui <- page_sidebar( title = "Doxazosin (Cardura) PK Simulator", theme = app_theme, sidebar = sidebar( title = "Simulation Settings", width = 340, h6("Dosing"), selectInput("dose", "Dose (mg)", choices = c(1, 2, 4, 8, 16), selected = 4), sliderInput("interval", "Dosing Interval (h)", min = 12, max = 24, value = 24, step = 12), numericInput("n_days", "Duration (days)", value = 5, min = 1, max = 14), hr(), h6("Patient Characteristics"), sliderInput("wt", "Weight (kg)", min = 40, max = 120, value = 70, step = 5), sliderInput("hepf", "Hepatic Function (fraction)", min = 0.2, max = 1.0, value = 1.0, step = 0.1), hr(), checkboxInput("log_scale", "Log Scale (Y-axis)", value = FALSE) ), navset_card_tab( title = "Doxazosin PK Simulator", full_screen = TRUE, nav_panel("Simulation", layout_column_wrap( width = 1/4, fill = FALSE, div(class = "metric-card metric-success", div(class = "metric-value", textOutput("cmax")), div(class = "metric-label", "Cmax (ng/mL)")), div(class = "metric-card metric-warning", div(class = "metric-value", textOutput("ctrough")), div(class = "metric-label", "Ctrough (ng/mL)")), div(class = "metric-card metric-primary", div(class = "metric-value", textOutput("auc")), div(class = "metric-label", "AUC0-\u03c4 (ng\u00b7h/mL)")), div(class = "metric-card metric-info", div(class = "metric-value", textOutput("thalf")), div(class = "metric-label", "t\u00bd (h)")) ), plotOutput("pkPlot", height = "500px") ), nav_panel("Model Information", markdown(" ## Doxazosin (Cardura) — 1-Compartment Oral PK Model **Structure:** One-compartment with first-order absorption **Clearance:** 6.3 L/h (1.5 mL/min/kg for 70 kg; scaled by weight and hepatic function) **Volume of Distribution:** 105 L (1.5 L/kg for 70 kg) **Ka:** 1.25 h\u207b\u00b9 (Tmax ~ 2\u20133 h) **Bioavailability:** 65% **Protein Binding:** 98.3% ### Pharmacokinetic Highlights - Rapidly absorbed after oral administration (Tmax 2\u20133 h) - Terminal elimination half-life: 10\u201312 h (single dose); up to 22 h (multiple dose) - Extensively metabolized in the liver: O-demethylation (23%), C-hydroxylation (12%) - Only ~5% excreted unchanged in urine - No active metabolites; pharmacologic activity directly related to plasma concentration - No dose-dependent or time-dependent changes in elimination (1\u201316 mg range) - Linear pharmacokinetics: plasma concentrations proportional to dose ### Therapeutic Context - **Class:** Alpha-1 adrenoceptor antagonist (quinazoline derivative) - **Indications:** Essential hypertension, benign prostatic hyperplasia (BPH) - **Dosing:** Start 1 mg once daily; titrate up to 2, 4, 8, or 16 mg daily - **Effective plasma range:** ~5\u201350 ng/mL (antihypertensive effect) - No significant PK differences between young and elderly patients ")), nav_panel("References", div(class = "ref-box", tags$h5("\U0001f4da Key References"), tags$ol( tags$li("Elliott HL, Meredith PA, Reid JL. (1987) Am J Cardiol 59:78G-81G \u2014 Pharmacokinetic overview of doxazosin"), tags$li("Vincent J, Elliott HL, Meredith PA, Reid JL. (1983) Br J Clin Pharmacol 15:719-725 \u2014 Doxazosin PK and concentration-effect relationships"), tags$li("Kaye B et al. (1986) Br J Clin Pharmacol 21(suppl 1):19s-25s \u2014 Metabolism and kinetics of doxazosin"), tags$li("Vincent J, Meredith PA, Elliott HL, Reid JL. (1986) Br J Clin Pharmacol 21:1-4 \u2014 PK of doxazosin in elderly normotensives"), tags$li("FDA Label: CARDURA (doxazosin mesylate) Tablets \u2014 NDA 019668") ), tags$h5("\U0001f48a Therapeutic Context"), tags$ul( tags$li(tags$strong("Class:"), " Alpha-1 adrenoceptor antagonist (quinazoline derivative)"), tags$li(tags$strong("Related to:"), " Prazosin (shorter t\u00bd ~2.5 h vs doxazosin ~11 h)"), tags$li(tags$strong("Doses:"), " 1, 2, 4, 8, 16 mg tablets; once daily"), tags$li(tags$strong("Route:"), " Oral"), tags$li(tags$strong("Metabolism:"), " Hepatic: O-demethylation (23%), C-hydroxylation (12%); low extraction ratio"), tags$li(tags$strong("Renal impairment:"), " No significant effect on PK (no dose adjustment needed)"), tags$li(tags$strong("Elderly:"), " No major PK differences; suitable for elderly patients") ) )) ), div(style = "text-align: center; padding: 20px; margin-top: 30px; border-top: 1px solid #e9ecef; color: #6c757d; font-size: 12px;", "Powered by ", tags$a(href = "https://www.pkpdbuilder.com", target = "_blank", style = "color: #8b5cf6; font-weight: 500;", "PKPDBuilder.com"), " \u2022 Built by Sunny \u2600\ufe0f (Husain Attarwala's AI Assistant)", br(), tags$span(style = "font-size: 10px;", "For research and educational purposes only. Not for clinical decision-making.")) ) server <- function(input, output, session) { sim_data <- reactive({ dose_mg <- as.numeric(input$dose) ev1 <- ev(amt = dose_mg, cmt = 1, ii = input$interval, addl = (input$n_days * 24 / input$interval) - 1) mod %>% param(WT = input$wt, HEPF = input$hepf) %>% ev(ev1) %>% mrgsim(end = input$n_days * 24, delta = 0.25) %>% as.data.frame() %>% mutate(time_h = time) }) output$cmax <- renderText({ d <- sim_data() last <- d %>% filter(time >= (input$n_days - 1) * 24) sprintf("%.1f", max(last$CP, na.rm = TRUE)) }) output$ctrough <- renderText({ d <- sim_data() last <- d %>% filter(time >= (input$n_days - 1) * 24) sprintf("%.1f", min(last$CP[last$CP > 0], na.rm = TRUE)) }) output$auc <- renderText({ d <- sim_data() last_start <- (input$n_days - 1) * 24 last <- d %>% filter(time >= last_start, time <= last_start + input$interval) auc <- sum(diff(last$time) * (head(last$CP, -1) + tail(last$CP, -1)) / 2) sprintf("%.1f", auc) }) output$thalf <- renderText({ CLi <- 6.3 * (input$wt / 70) * input$hepf Vi <- 105 * (input$wt / 70) sprintf("%.1f", log(2) / (CLi / Vi)) }) output$pkPlot <- renderPlot({ d <- sim_data() dose_mg <- as.numeric(input$dose) p <- ggplot(d, aes(x = time_h, y = CP)) + annotate("rect", xmin = -Inf, xmax = Inf, ymin = 5, ymax = 50, fill = "#10b981", alpha = 0.12) + geom_hline(yintercept = c(5, 50), linetype = "dashed", color = "#10b981", alpha = 0.6) + annotate("text", x = max(d$time_h) * 0.02, y = 53, label = "Effective range: 5-50 ng/mL", hjust = 0, size = 3.5, color = "#10b981") + geom_line(color = "#8b5cf6", linewidth = 0.8) + labs( x = "Time (hours)", y = "Plasma Concentration (ng/mL)", title = paste0("Doxazosin ", dose_mg, " mg Q", input$interval, "H") ) + theme_minimal(base_size = 14) if (input$log_scale) p <- p + scale_y_log10() p }) } shinyApp(ui = ui, server = server)