-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsc-usage.Rmd
242 lines (210 loc) · 6.38 KB
/
rsc-usage.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
---
title: "Steve's RStudio Connect Server Usage Edited - Last `r as.numeric(Sys.getenv('DAYSBACK', 30))` Days"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
css: styles.css
---
```{r preflight_check, results='asis', include=TRUE}
# ---------------------------------------------------------------------------
# this section is used to stop the report from rendering
# if important variables are missing (CONNECT_SERVER and CONNECT_API_KEY)
# ---------------------------------------------------------------------------
if (
nchar(Sys.getenv("CONNECT_SERVER")) == 0 ||
nchar(Sys.getenv("CONNECT_API_KEY")) == 0
) {
print(htmltools::h4("ERROR: Variables Not Defined"))
print(htmltools::div(
"The CONNECT_SERVER and CONNECT_API_KEY",
"environment variables are required in order for this report",
"to pull usage data.",
htmltools::br(),
htmltools::br(),
"Please define these variables",
"and then re-run the report.",
htmltools::br(),
htmltools::br(),
style = "max-width: 600px"
))
knitr::knit_exit("Terminating the report early.")
}
```
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(DT)
library(plotly)
library(ggplot2)
library(shiny)
library(lubridate)
library(blastula)
library(prettyunits)
library(connectapi)
source("themes.R")
days_back <- as.numeric(Sys.getenv("DAYSBACK", 30))
default_content_title <- "Unknown (Deleted Content?)"
report_from <- lubridate::today() - lubridate::ddays(days_back)
client <- connect()
shiny <- get_usage_shiny(
client,
from = report_from,
limit = Inf
) %>%
mutate(
started = lubridate::ymd_hms(started),
ended = lubridate::ymd_hms(ended),
session_duration = ended - started
) %>%
filter(session_duration > lubridate::dseconds(5))
content <- get_usage_static(
client,
from = report_from,
limit = Inf
)
all_users <- get_users(client, page_size = 500)
data_arr <- list(shiny = shiny, content = content)
```
This content summary may contain privileged information. The report is generated
using the [RStudio Connect Server API](http://docs.rstudio.com/connect/api) and
the source code is [available online](https://github.com/sol-eng/connect-usage)
if you'd like to customize your analysis. Data is limited to the last
`r days_back` days.
The report uses the environment variables `CONNECT_SERVER` and `CONNECT_API_KEY`
to collect the data. To limit the results to a single publisher, use a publisher
API key.
Column
-----------------------------------------------------------------------
### Shiny Sessions by User (Top 5)
```{r shiny_by_user}
data_arr$shiny %>%
group_by(user_guid) %>%
summarise(visits = n()) %>%
left_join(all_users, by = c(user_guid = "guid")) %>%
mutate(username = coalesce(username, "anonymous")) %>%
select(username, visits) %>%
arrange(desc(visits)) %>%
head(5) %>%
{ggplot(., aes(reorder(username, visits), visits)) +
geom_bar(stat = "identity") +
coord_flip() +
theme_rstudio() +
labs(
y = "Number of Shiny Sessions",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
config(displayModeBar = F)
```
### Static Content Hits by User (Top 5)
```{r static_by_user}
data_arr$content %>%
group_by(user_guid) %>%
summarise(visits = n()) %>%
left_join(all_users, by = c(user_guid = "guid")) %>%
mutate(username = coalesce(username, "anonymous")) %>%
select(username, visits) %>%
arrange(desc(visits)) %>%
head(5) %>%
{ggplot(., aes(reorder(username, visits), visits)) +
geom_bar(stat = "identity") +
coord_flip() +
theme_rstudio() +
labs(
y = "Number of Content Visits",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
config(displayModeBar = F)
```
Column
-----------------------------------------------------------------------
### Shiny Sessions Over Time
```{r shiny_over_time}
data_arr$shiny %>%
mutate(day = round_date(started, "day")) %>%
filter(day > today() - ddays(days_back)) %>%
group_by(day) %>%
summarise(visits = n()) %>%
arrange(desc(visits)) %>%
{ggplot(., aes(day, visits)) +
geom_point() +
geom_smooth(se = FALSE) +
theme_rstudio() +
labs(
y = "# of Shiny Sessions",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
config(displayModeBar = F)
```
### Static Content Visits Over Time
```{r static_over_time}
data_arr$content %>%
mutate(time = ymd_hms(time),
day = round_date(time, "day")) %>%
filter(day > today() - ddays(days_back)) %>%
group_by(day) %>%
summarise(visits = n()) %>%
arrange(desc(visits)) %>%
{ggplot(., aes(day, visits)) +
geom_point() +
geom_smooth(se = FALSE) +
theme_rstudio() +
labs(
y = "Content Hits",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
config(displayModeBar = F)
```
Column
-----------------------------------------------------------------------
### Top Applications
```{r top_shiny}
data_arr$shiny %>%
group_by(content_guid) %>%
summarize(visits = n()) %>%
arrange(desc(visits)) %>%
head() %>%
mutate(name = purrr::map_chr(content_guid, ~ content_title(client, .x, default_content_title))) %>%
{ggplot(., aes(reorder(stringr::str_wrap(name, 30), visits), visits)) +
geom_bar(stat = "identity") +
coord_flip() +
theme_rstudio() +
labs(
y = "# of Shiny Sessions",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
layout(margin = list(l = 0)) %>%
config(displayModeBar = F)
```
### Top Static Content
```{r top_static}
data_arr$content %>%
group_by(content_guid) %>%
summarize(visits = n()) %>%
arrange(desc(visits)) %>%
head() %>%
mutate(name = purrr::map_chr(content_guid, ~ content_title(client, .x, default_content_title))) %>%
{ggplot(., aes(reorder(stringr::str_wrap(name, 30), visits), visits)) +
geom_bar(stat = "identity") +
coord_flip() +
theme_rstudio() +
labs(
y = "Content Hits",
x = NULL
)} %>%
ggplotly(tooltip = c("y")) %>%
layout(margin = list(l = 0)) %>%
config(displayModeBar = F)
```
```{r render_custom_email}
render_connect_email(input = "usage-email.Rmd") %>%
attach_connect_email(
subject = sprintf(" Content Usage Report For %s", month(today(), label = TRUE, abbr = FALSE)),
attach_output = TRUE
)
```