-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
251 lines (211 loc) · 7.79 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
---
title: "rLocker"
output:
md_document:
variant: gfm
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
eval = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rLocker <img src="https://github.com/EducationShinyAppTeam/rLocker/blob/master/rLocker.png?raw=true" align="right" height=140>
<!-- badges: start -->
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/rLocker)](https://cran.r-project.org/package=rLocker)
[![License: GPLv3](https://img.shields.io/github/license/EducationShinyAppTeam/rLocker.svg?style=flat)](https://opensource.org/licenses/GPL-3.0)
<!-- badges: end -->
Learning Locker xAPI support for Shiny Applications.
### About xAPI
> xAPI \[Experience API\] is 100% free, open source, lightweight, and adaptable. It can be used to augment almost any performance assessment situation. It is being used in an expanding array of learning systems, from LMSs and simulator systems to museums and emergency medical services. – [adlnet.gov](https://adlnet.gov/projects/xapi/)
See also: [What is the Experience API?](https://xapi.com/overview/)
### Assumptions
1. This package assumes that you have a [Learning Locker](https://www.ht2labs.com/learning-locker-community/overview/) instance set up and that it's reachable by your application.
2. Your application is running in an environment that supports [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS); otherwise API requests will be blocked. Requests made from `localhost` \/ `127.0.0.1` \/ RStudio's `runApp()` are often blocked for this reason.
3. You are given consent by the application user(s) to collect activity data on them. **Note**: unless specified, user identifiers are anonymized by default.
### Installation
You can install the released version of rLocker from [GitHub](https://github.com/) with:
```{r}
devtools::install_github("EducationShinyAppTeam/rLocker")
```
### Examples
See the [examples](./inst/examples/) folder for demo code or visit [psu-eberly.shinyapps.io/rLocker](https://psu-eberly.shinyapps.io/rLocker) to see it in action.
### Storage Mechanism
Below are two approaches to creating and storing a simple xAPI statement in Learning Locker.
#### Method 1: R handler
###### app.R
```{r}
library(shiny)
library(rLocker)
shinyApp(
server = function(input, output, session) {
# Initialize Learning Locker connection -- substitute with your own locker credentials
rLocker::connect(session, list(
base_url = "https://learning-locker.example.com/",
endpoint = "/data/xAPI/",
auth = "Basic YWNjb3VudEBlbWFpbC5jb206c3VwZXJzZWNyZXRwYXNzd29yZA"
))
# Register input event for interactive elements
observeEvent(input$button, {
statement <- rLocker::createStatement()
rLocker::store(statement)
})
}
)
```
#### Method 2: JavaScript handler
###### app.R
```{r}
library(shiny)
library(rLocker)
shinyApp(
ui = fluidPage(
# Attach js logic
tags$script(src = "js/app.js"),
# Application title
titlePanel("rLocker demo"),
fluidRow(
actionButton("button", "Press me!")
)
),
server = function(input, output, session) {
# Initialize Learning Locker connection -- substitute with your own locker credentials
config <- jsonlite::toJSON(
list(
base_url = "https://learning-locker.example.com/",
endpoint = "/data/xAPI/",
auth = "Basic YWNjb3VudEBlbWFpbC5jb206c3VwZXJzZWNyZXRwYXNzd29yZA"
),
pretty = TRUE,
auto_unbox = TRUE,
force = TRUE
)
session$sendCustomMessage(type = 'rlocker-setup', config)
# Register input events for interactive elements
observeEvent(input$button, {
session$sendCustomMessage(type = 'rlocker-store', rLocker::createStatement())
})
}
)
```
###### www/js/app.js
```{js}
Shiny.addCustomMessageHandler('rlocker-setup', function(config) {
/* connection logic */
});
Shiny.addCustomMessageHandler('rlocker-store', function(values) {
/* storage logic */
});
```
See [adlnet/xAPIWrapper](https://github.com/adlnet/xAPIWrapper/) for JavaScript implementations.
### Data Retreival
Stored statements can be retreived from Learning Locker by using the `retrieve` method.
**Note**: This requires a connection to be established by the R-handler to work; JS implementations can interface with the API through [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) instead.
###### app.R
```{r}
response <- rLocker::retrieve(
interface = "connection",
model = "statement",
query = "first=1",
asJSON = TRUE
)
print(response)
```
Response data can be returned as a JSON formatted string or as an R object (default). Below is sample output from the request above.
###### OUTPUT JSON
```{json}
{
"edges": [
{
"cursor": "eyJfaWQiOiI1YzQ2MmRiYjI0ZjVmMDRhOTI0MjZlMWMifQ==",
"node": {
"person": {},
"completedQueues": [],
"processingQueues": [],
"deadForwardingQueue": [],
"pendingForwardingQueue": [],
"completedForwardingQueue": [],
"_id": "5c462dbb24f5f04a92426e1c",
"hasGeneratedId": false,
"organisation": "5c4383e369b9834b4e086caa",
"lrs_id": "5c46260e85ce554a24b7579f",
"client": "5c46260e85ce554a24b757a0",
"active": true,
"voided": false,
"timestamp": "2019-01-21T20:38:19.131Z",
"stored": "2019-01-21T20:38:19.131Z",
"hash": "0905ec8aa05e67d247d7c888baf80b1f65c439c9",
"agents": [
"886b382eb3a9570aeb3da9b34028a76ed761f1b9"
],
"relatedAgents": [
"886b382eb3a9570aeb3da9b34028a76ed761f1b9",
"mailto:hello@learninglocker.net"
],
"registrations": [],
"verbs": [
"http://adlnet.gov/expapi/verbs/launched"
],
"activities": [
"http://127.0.0.1:4358/"
],
"relatedActivities": [
"http://127.0.0.1:4358/"
],
"statement": {
"actor": {
"objectType": "Agent",
"name": "b5958c7b-22ba-404f-af7d-e5c3ccc6ddea",
"mbox_sha1sum": "886b382eb3a9570aeb3da9b34028a76ed761f1b9"
},
"verb": {
"id": "http://adlnet.gov/expapi/verbs/launched",
"display": {
"en-US": "launched"
}
},
"object": {
"objectType": "Activity",
"id": "http://127.0.0.1:4358/",
"definition": {
"name": {
"en-US": "rLocker demo"
}
}
},
"id": "baa14dff-fbb2-4722-94a2-ecb268193436",
"timestamp": "2019-01-21T20:38:19.131Z",
"stored": "2019-01-21T20:38:19.131Z",
"authority": {
"objectType": "Agent",
"name": "New Client",
"mbox": "mailto:hello@learninglocker.net"
},
"version": "1.0.0"
},
"failedForwardingLog": []
}
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "eyJfaWQiOiI1YzQ2MmRiYjI0ZjVmMDRhOTI0MjZlMWMifQ==",
"endCursor": "eyJfaWQiOiI1YzQ2MmRiYjI0ZjVmMDRhOTI0MjZlMWMifQ=="
}
}
```
See [HTTP Queries](https://docs.learninglocker.net/http-queries/) for more information on how to make calls to the records database.
### Configuration
|option|default|
|---|---|
|base_url|http://localhost:8000/xapi/|
|endpoint|/data/xAPI/|
|auth|Basic YWNjb3VudEBlbWFpbC5jb206c3VwZXJzZWNyZXRwYXNzd29yZA|
|username|null|
|password|null|
**Note**: *base_url* should be the hosting location for your locker's API *without* any endpoint or home.