← Back to team overview

dhis2-users team mailing list archive

Re: Connect to data

 

The proxy can be rather easily set by setting the curl options with
something like...

curl <- getCurlHandle()
curlSetOpt(.opts = list(proxy = '<address>:<port>'), curl = curl)
response<- getURL('http://mydhis',..., curl = curl)

Depends a bit on your proxy of course, so you may have to experiment a bit.

Regards,
Jason



On Wed, May 23, 2012 at 7:58 AM, <hiattt@xxxxxxxxxxxx> wrote:
>
> Wow, you’ve saved me like a week’s worth of life!
>
>
>
> I’m having proxy issues here at work, but I’ll try it when I get home. I’ll try and get it to work first, then take on the connection issues.
>
>
>
> Thanks!
>
> Tom
>
>
>
> ________________________________
>
> From: Jason Pickering [mailto:jason.p.pickering@xxxxxxxxx]
> Sent: 23 May 2012 12:48
>
>
> To: Hiatt, Mr Tom (WPRO)
> Cc: larshelge@xxxxxxxxx; dhis2-users@xxxxxxxxxxxxxxxxxxx
>
> Subject: Re: [Dhis2-users] Connect to data
>
>
>
> Hi Tom and Lars,
>
>
>
> The following R code will retrieve the data as per Lars example, and place this into  an R data frame. Maybe this will help to get you started.
>
>
>
> Best Regards,
>
> Jason
>
>
>
>
>
> library(RCurl)
>
> h = basicTextGatherer()
>
> response<-getURL("http://apps.dhis2.org/dev/api/reportTables/data.csv?de=fbfJHSPpUQD&de=cYeuwXTCPkU&in=Uvn6LCg7dVU&ou=O6uvpzGd5pu&last12Months=true
>
> ",userpwd="admin:district",httpauth = 1L,
>
> header=TRUE,headerfunction=h$update)
>
> #Ugly hack to get ride of the header
>
> stripme<-paste("HTTP/1.1 200 OK\r\n",paste(h$value(NULL)[-1], collapse=""),sep="")
>
> data<-gsub(stripme,"",response)
>
> #Unquote the data
>
> data<-noquote(data)
>
> #here is the data.
>
> foo<-read.table(textConnection(data),sep=",",header=T)
>
>
>
>
>
> On Wed, May 23, 2012 at 5:17 AM, <hiattt@xxxxxxxxxxxx> wrote:
>
> Thanks, Lars. This is great and very useful! Now I just have to figure out how to have R pass those parameters to the URL and then return the CSV file into R.
>
>
>
> Thanks again,
>
> Tom
>
>
>
>
>
> ________________________________
>
> From: Lars Helge Øverland [mailto:larshelge@xxxxxxxxx]
> Sent: 23 May 2012 06:03
>
>
> To: Hiatt, Mr Tom (WPRO)
>
> Cc: jason.p.pickering@xxxxxxxxx; dhis2-users@xxxxxxxxxxxxxxxxxxx
>
>
> Subject: Re: [Dhis2-users] Connect to data
>
>
>
> Hi Tom,
>
>
>
> if you refer to aggregated data (from the aggregated* tables) there is a way to do this - unfortunately it is in trunk only and not documented yet - will try a quick explanation here:
>
>
>
> To get the aggregated data you can interact with the reportTables resource. First you need to look up the ids (uids) of the data elements, indicators, org units you need using the api starting here (from the snapshot demo in this example):
>
>
>
> http://apps.dhis2.org/dev/api/resources
>
>
>
> You can then retrieve the data like this :
>
>
>
> http://apps.dhis2.org/dev/api/reportTables/data.xml?de=fbfJHSPpUQD&de=cYeuwXTCPkU&in=Uvn6LCg7dVU&ou=O6uvpzGd5pu&last12Months=true
>
>
>
> You can substitute ".xml" with any of ".json", ".jsonp", ".csv", ".pdf", ".xls", ".html".
>
>
>
> You can repeat the de, in and ou query params as many times you want to get data for multiple meta-data objects.
>
>
>
> Valid params for periods are
>
>
>
>
>
> reportingMonth
>
> reportingBimonth
>
> reportingQuarter
>
> lastSixMonth
>
> monthsThisYear
>
> quartersThisYear
>
> thisYear
>
> monthsLastYear
>
> quartersLastYear
>
> lastYear
>
> last5Years
>
> last12Months
>
> last6BiMonths
>
> last4Quarters
>
> last2SixMonths
>
> thisFinancialYear
>
> lastFinancialYear
>
> last5FinancialYears
>
> last52Weeks
>
>
>
>
>
>
>
> Let me know it this helps. Lars
>
>
>
>
>
> ________________________________
>
> This message was scanned for viruses with Trend Micro ScanMail, GFI MailSecurity and GFI MailEssentials by the World Health Organization Regional Office for the Western Pacific. However, the recipient is advised to scan this e-mail and any attached files for viruses.
>
> Disclaimer:
>
> This e-mail, together with any attachments, is intended for the named recipients only and is confidential. It may also be privileged or otherwise protected by law.
>
> If you have received it in error, please notify the sender immediately by reply e-mail and delete it and any attachments from your system. You may not copy or disclose its contents to anyone.
>
>
>
>
>
>
>
> ________________________________
>
> This message was scanned for viruses with Trend Micro ScanMail, GFI MailSecurity and GFI MailEssentials by the World Health Organization Regional Office for the Western Pacific. However, the recipient is advised to scan this e-mail and any attached files for viruses.
>
> Disclaimer:
>
> This e-mail, together with any attachments, is intended for the named recipients only and is confidential. It may also be privileged or otherwise protected by law.
>
> If you have received it in error, please notify the sender immediately by reply e-mail and delete it and any attachments from your system. You may not copy or disclose its contents to anyone.


References