← Back to team overview

dhis2-devs team mailing list archive

DHIS2 with R

 

Hi everyone. I have had a recent question from a user about how DHIS2
can be used with R. I am including a trivial example here about how to
use R as as a client to access data and produce a graph in DHIS2.

Just get a copy of R  and install the DBI and RPostregSQL packages with

>install.packages()


After that, just connect to the DB, retrieve your data (in this case
from a report table) and produce a graph.

>library(DBI)

>library(RPostgreSQL)

>drv <- dbDriver("PostgreSQL")

>con <- dbConnect(drv, dbname="dhis2_zm_prod2", user="postgres", password="postgres")

>rs <- dbSendQuery(con, "SELECT * FROM _report_malaria_indicators_district where
organisationunitid = 3904")

>data <- fetch(rs,n=-1)

>barplot(data$malaria_confirm_incidence, names.arg=as.character(data$periodname), main=as.character(data$organisationunitname[1]),las=2)

>dev.print(png, file="/home/jason/test.png")

Regards,
Jason

---
Jason P. Pickering
email: jason.p.pickering@xxxxxxxxx
tel:+260968395190



Follow ups