inst/app/www/R_output/tab_1_prescriptions_diagnosis.R

output$tab_1_prescriptions_diagnosis_OPD <- renderHighchart({
  req(patients_filter())
  req(patients_filter() %>% filter(ipdopd == "Outpatient") %>% nrow() > 1)
  
  dta <- patients_filter() %>%
    filter(ipdopd == "Outpatient") %>%
    group_by(diasite) %>%
    count() %>%
    ungroup() %>%
    arrange(desc(n)) %>%
    mutate(color = colors_ipd_opd[["OPD"]]) %>%
    mutate(total_presciptions = sum(n)) %>%
    mutate(pct = round(100*n / total_presciptions, 1))
  
  hchart(dta, type = "column", hcaes(x = diasite, y = pct, color = color)) %>%
    hc_tooltip(headerFormat = "", pointFormat = "{point.pct}% <br>({point.n} of {point.total_presciptions} outpatient prescriptions)") %>%
    hc_title(text = "Outpatient") %>%
    hc_yAxis(title = list(text = "% of Outpatient Prescriptions")) %>%
    hc_xAxis(title = "")
})

output$tab_1_prescriptions_diagnosis_IPD <- renderHighchart({
  req(patients_filter())
  req(patients_filter() %>% filter(ipdopd == "Inpatient") %>% nrow() > 1)
  
  dta <- patients_filter() %>%
    filter(ipdopd == "Inpatient") %>%
    group_by(diasite) %>%
    count() %>%
    ungroup() %>%
    arrange(desc(n)) %>%
    mutate(color = colors_ipd_opd[["IPD"]]) %>%
    mutate(total_presciptions = sum(n)) %>%
    mutate(pct = round(100*n / total_presciptions, 1))
  
  hchart(dta, type = "column", hcaes(x = diasite, y = pct, color = color)) %>%
    hc_tooltip(headerFormat = "", pointFormat = "{point.pct}% <br>({point.n} of {point.total_presciptions} inpatient prescriptions)") %>%
    hc_title(text = "Inpatient") %>%
    hc_yAxis(title = list(text = "% of Inpatient Prescriptions")) %>%
    hc_xAxis(title = "")
})
ocelhay/AMULaos documentation built on Oct. 29, 2020, 5:54 a.m.