dhis2r
is an R client for the DHIS2 web API.
Pull data from a DHIS2 instance into R without logging into the DHIS2 user interface.
dhis2r
, if used with Rmarkdown, quarto, Rshiny, etc.,
can improve routine reporting and data requests.
DHIS2 is an open-source, web-based Health Management Information System (HMIS), and currently being adopted in the education sector as the Education Management Information System (EMIS) in several countries.
More than 73 countries worldwide use DHIS2 for collecting and analyzing health data. 2.4 billion people (30% of the world’s population) live in countries where DHIS2 is used. (source: https://dhis2.org/)
With the increasing number of data managers/analysts downloading data from DHIS2 instances to make routine period reports, data visualisation and dashboards, this R package can make it much easier to pull the required data.
There are over 2 million R users, some of whom periodically analyse data from DHIS2; and support health programs which affect over the 2.4 billion people.
You can install the stable version of dhis2r from CRAN with:
install.packages("dhis2r")
You can install also the development version of dhis2r from GitHub with:
# install.packages("devtools")
::install_github("amanyiraho/dhis2r") devtools
Users must be authenticated to access a specific DHIS2 instance before connecting to it. You can use
username
and password
Personal Access Token (PAT)
username
and
password
The easiest way to connect to a DHIS2 instance using dhis2r is to use
the username
and password
of the DHIS2
user.
library(dhis2r)
<- Dhis2r$new(base_url = "https://play.im.dhis2.org/stable-2-40-5",
dhis2_play_connection username = "admin",
password = "district")
Alternatively you can generate a personal access token and use that to connect.
library(dhis2r)
# Replace the value of api_token with the token you have generated
<- Dhis2r$new(base_url = "https://play.im.dhis2.org/stable-2-40-5",
dhis2_play_connection api_token = "d2pat_2EkxmqdxtwAGDGe1hXzpWEixYdvHGRw71587176066")
Dhis2r$new()
returns a Dhis2r
R6 class
which represents a DHIS2 connection and can be used to query the DHIS2
instance
No need to log in again when performing other querying tasks.
As an example, let’s pull Analytics data of
BCG doses given
Analytics data can include data from indicators, dataElements, program indicators, etc.
$get_analytics(analytic = "s46m5MS0hxu", #BCG doses given
dhis2_play_connectionorg_unit = "ImspTQPwCqd", #Sierra Leone (National level)
period = "202101",
output_scheme = "NAME" )
You can pull data on the following:
For more in depth illustration use the vignette dhis2r
vignette("dhis2r")
Please note that the dhis2r project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.