inst/app/www/R_output/tab_1_number_prescribed.R

output$tab_1_number_prescribed <- renderHighchart({
  req(patients_filter())
  req(patients_filter() %>% nrow() > 1)
  
  dta <- patients_filter() %>%
    group_by(patient_id, ipdopd) %>%
    summarise(uni = n_distinct(antiname), .groups = "drop") %>%
    mutate(uni = case_when(
      uni == 1 ~ "1 Antimicrobial Agent",
      uni == 2 ~ "2 Antimicrobial Agents",
      uni >= 3 ~ "3+ Antimicrobial Agents"
    )) %>%
    group_by(ipdopd) %>%
    count(uni) %>%
    ungroup() %>%
    complete(ipdopd, uni, fill = list(n = 0)) %>%
    mutate(total_patients_prescribed = sum(n)) %>%
    mutate(pct = round(100*n / total_patients_prescribed, 1))
  
  hchart(dta, type = "column", hcaes(x = uni, y = pct, group = ipdopd)) %>%
    hc_colors(as.vector(colors_ipd_opd)[c("Inpatient" %in% dta$ipdopd, "Outpatient" %in% dta$ipdopd)]) %>%
    hc_tooltip(headerFormat = "", pointFormat = "{point.pct}% <br>({point.n} of {point.total_patients_prescribed} patients)") %>%
    hc_yAxis(title = list(text = "% of Patients")) %>%
    hc_xAxis(title = "")
})
ocelhay/AMULaos documentation built on Oct. 29, 2020, 5:54 a.m.