Coder Social home page Coder Social logo

advanced-r-programming-5's Introduction

Advanced-r-programming-5

Build Status

Repository for the course 732A94 Advanced Programming in R at Linköping University 2018. Assignment 5.

We are going to use the Kolada API. The format is perfect (JSON), the API has a documentation and follows the REST principle. The documentation can be found here.

A Tutorial how to consume a REST-API in R can be found here.

The packages needed are httr for the HTTP communication and jsonlite for mapping JSON data to data.frames.

Example for REST-Call

This is an example how the libraries can be used to fetch data. Be aware, that this example does not handle pagination.

library(httr)
library(jsonlite)

# Prepare Call
base = "http://api.kolada.se/"
endpoint = "v1/ou/data/peryear/N15030/2011"
webCall = paste(base, endpoint, sep="")

# Execution
response = GET(webCall)

# Deserialization
result = content(response, "text", encoding = "utf-8")
result.data.frame = as.data.frame(fromJSON(result, flatten = TRUE))

For this call, the response looks like this:

> head(result.data.frame)
  values.kpi    values.ou values.period values.value values.value_m values.value_f                                                                   next. count
1     N15030 V150114G0R01          2011         84.4             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100
2     N15030 V150114G0R02          2011         81.8             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100
3     N15030 V150115G0R01          2011         84.3             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100
4     N15030 V150115G0R02          2011         62.1             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100
5     N15030 V150117G0R01          2011         84.8             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100
6     N15030 V150117G0R02          2011         76.4             NA             NA http://api.kolada.se/v1/ou/data/peryear/N15030/2011?page=2&per_page=100   100

Execution of the shiny- App

devtools::install_github("rubenjmunoz/advanced-r-programming-5", build_vignettes = TRUE)

library(shiny)
runGitHub('advanced-r-programming-5','rubenjmunoz')

devtools::use_vignette("advanced_r_5")

advanced-r-programming-5's People

Contributors

flennic avatar rubenjmunoz avatar annalenae avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.