Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Last active October 2, 2018 10:43
Show Gist options
  • Save stephlocke/053e047b9a41dcb1fd9fe181e5b5ba1c to your computer and use it in GitHub Desktop.
Save stephlocke/053e047b9a41dcb1fd9fe181e5b5ba1c to your computer and use it in GitHub Desktop.
sunburst wip
---
title: "IBM Personality Insights"
output: html_notebook
---
```{r setup, include=FALSE, warning=FALSE, message=FALSE}
if(!require(httr)) install.packages("httr")
if(!require(listviewer)) install.packages("listviewer")
if (!require(ibmsunburst)) remotes::install_github("lockedata/ibmsunburst")
```
# Auth
```{r}
key = "aOWMNztQ_VVlz9fINhc3v67rtnJqcN6JuubQorAvhIDq"
url = "https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13"
uname="a4a4ea65-e8e7-492c-a95e-128f1460fc5f"
pword="LuFm4BERGhLs"
```
# Requests
Sample script from tutorial:
```bash
curl -X POST --user "apikey:{apikey}" \
--header "Content-Type: text/plain;charset=utf-8" \
--header "Accept: application/json" \
--data-binary @{path_to_file}profile.txt \
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13"
```
Converted to httr:
```{r}
library(httr)
cr=POST(url,
authenticate(uname, pword),
content_type("text/plain;charset=utf-8"),
accept_json(),
body=upload_file("sample_profile.txt")
)
status_code(cr)
```
## Response structure
```{r}
library(listviewer)
insightdata = content(cr)
jsonedit(insightdata)
```
# Visualising sunbursts
```{r error=TRUE}
library(ibmsunburst)
ibmsunburst(insightdata)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment