Skip to content

Commit 4572c0f

Browse files
authored
Merge pull request #5 from Appsilon/copy-user-metrics
add connect-user-metrics dir
2 parents fbab422 + 94e6b43 commit 4572c0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13614
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if (file.exists("renv")) {
2+
source("renv/activate.R")
3+
} else {
4+
# The `renv` directory is automatically skipped when deploying with rsconnect.
5+
message("No 'renv' directory found; renv won't be activated.")
6+
}
7+
8+
# Allow absolute module imports (relative to the app root).
9+
options(box.path = getwd())
10+
11+
if (nzchar(system.file(package = "box.lsp"))) {
12+
options(
13+
languageserver.parser_hooks = list(
14+
"box::use" = box.lsp::box_use_parser
15+
)
16+
)
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Renviron
2+
.Rproj.user
3+
.Rhistory
4+
.DS_Store
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
linters:
2+
linters_with_defaults(
3+
defaults = box.linters::rhino_default_linters,
4+
line_length_linter = line_length_linter(100)
5+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Only use `dependencies.R` to infer project dependencies.
2+
*
3+
!dependencies.R
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.github
2+
.lintr
3+
.renvignore
4+
.Renviron
5+
.rhino
6+
.rscignore
7+
tests
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Connect Insights Dashboard
2+
Expected output: repository with ready-to-use tool. Deploy, set env vars, and enjoy!
3+
Repository for a reproducible tool to share user metrics for Posit Connect deployed applications.
4+
5+
Expected deployment time: only 5 minutes!
6+
7+
## Quickstart
8+
To get insights about applications deployed by you, simply deploy the application to Posit Connect.
9+
10+
If you wish to run the application locally, set the required [Environment Variables](#environment-variables),
11+
and run `shiny::runApp()` from the root of this repository.
12+
13+
## Environment Variables
14+
This application requires the following environment variables to be set:
15+
- `CONNECT_API_KEY`
16+
- `CONNECT_SERVER`
17+
18+
By default, Posit Connect provides values for these variables, as outlined in the [Vars (Environment Variables) Section][User Guide Vars].
19+
However, there are cases where you might want to set these variables manually:
20+
- If you want to retrieve data for applications deployed by a different Publisher than the one
21+
deploying the User Metrics application, set `CONNECT_API_KEY` with that Publisher's API key.
22+
- If you want to retrieve data from a different Posit Connect instance than the one where the User
23+
Metrics application is deployed, set `CONNECT_SERVER` with the URL of that instance.
24+
Additionally, `CONNECT_API_KEY` must be set to authenticate on the instance specified in
25+
`CONNECT_SERVER`.
26+
27+
Additionally, if only selected applications should be included, use the `GUIDS` environment variable and provide the GUIDs of all the apps to be measured, separated by a single comma (no spaces):
28+
```r
29+
GUIDS=4203ee4b-16c5-452d-9509-712e29a0d3fb,d358a2e9-e166-4239-978c-d26e9ba82f71
30+
```
31+
32+
### Deployment with an API Key
33+
To deploy an app using the RSConnect API Key, use the following code:
34+
35+
```r
36+
rsconnect::connectApiUser(server = "connect.appsilon.com", apiKey = "<token>", account = "support")
37+
rsconnect::accounts() # list accounts
38+
rsconnect::deployApp(account = "support", appName = "appName")
39+
```
40+
41+
## Default inputs configuration [with optional parameters]
42+
By default, this application selects all users and all applications to be displayed in the summary charts and tables when launched.
43+
The applications and users to include, as well as the aggregation level, can be configured without the need to manually set these options through the UI.
44+
To do this, specify the parameters in a `config.yml` file located in the root directory, using the following structure:
45+
46+
```yaml
47+
default:
48+
apps: "app1, app2"
49+
users: "user1, user2, user3"
50+
agg_levels: "user_guid, start_date"
51+
agg_time: "day"
52+
min_time: "00:02:00"
53+
unique_users_goal: "10"
54+
sessions_goal: "50"
55+
```
56+
57+
* **apps***: The app title as shown in Posit Connect.
58+
* **users***: The publisher's username.
59+
* **agg_levels**: The aggregation level — can be: content_guid, user_guid, and/or start_date.
60+
* **agg_time**: The aggregation frequency — can be: day, week, or month.
61+
* **min_time**: The minimum session duration to filter data and plots. Use format "hh:mm:ss".
62+
* **unique_users_goal***: Y-axis value for the goal line in the Unique Users plot.
63+
* **sessions_goal***: Y-axis value for the goal line in the Total Sessions plot.
64+
* **week_start**: The day to be used as the start of the week.
65+
66+
_* Optional YAML parameters._
67+
68+
Multiple parameters can be listed and separated by commas. For example, the `config.yml` above specifies two apps (*app1*, *app2*), three users (*user1*, *user2*, *user3*), and two aggregation levels (*user_guid* and *start_date*).
69+
70+
### Specifying goals
71+
You can specify the goal in three different ways for both `unique_users_goal` and `sessions_goal`.
72+
73+
1. Not specified — no goal is displayed:
74+
```yaml
75+
default:
76+
apps: ""
77+
users: ""
78+
agg_levels: "start_date" # can be one of content_guid,user_guid,start_date
79+
agg_time: "day" # can be one of day,week,month
80+
min_time: "00:02:00"
81+
week_start: "monday"
82+
```
83+
84+
2. Single value for all aggregation levels (e.g., date and combinations like app, user, date):
85+
```yaml
86+
default:
87+
apps: ""
88+
users: ""
89+
agg_levels: "start_date" # can be one of content_guid,user_guid,start_date
90+
agg_time: "day" # can be one of day,week,month
91+
min_time: "00:02:00"
92+
unique_users_goal: "20"
93+
sessions_goal: "10"
94+
week_start: "monday"
95+
```
96+
97+
3. Individual goals as a YAML list:
98+
```yaml
99+
default:
100+
apps: ""
101+
users: ""
102+
agg_levels: "start_date"
103+
agg_time: "day"
104+
min_time: "00:02:00"
105+
unique_users_goal:
106+
- freq: "day"
107+
per: "start_date"
108+
goal: "7"
109+
- freq: "day"
110+
per: "start_date,content_guid"
111+
goal: "14"
112+
- freq: "week"
113+
per: "start_date"
114+
goal: "10"
115+
sessions_goal:
116+
- freq: "day"
117+
per: "start_date"
118+
goal: "27"
119+
- freq: "day"
120+
per: "start_date,content_guid"
121+
goal: "84"
122+
- freq: "week"
123+
per: "start_date"
124+
goal: "30"
125+
week_start: "monday"
126+
```
127+
128+
Note: You can mix and match — for example, define `unique_users_goal` and leave `sessions_goal` unspecified:
129+
```yaml
130+
default:
131+
apps: ""
132+
users: ""
133+
agg_levels: "start_date" # can be one of content_guid,user_guid,start_date
134+
agg_time: "day" # can be one of day,week,month
135+
min_time: "00:02:00"
136+
unique_users_goal: "20"
137+
week_start: "monday"
138+
```
139+
140+
## Features
141+
142+
### Filtering users
143+
You can exclude specific users from appearing in any part of the application by listing them in the `constants/filter_users.yml` file:
144+
145+
```yaml
146+
users:
147+
- user_1 # will not appear in the app
148+
- user_2 # will not appear in the app
149+
```
150+
151+
### Branding
152+
You can use the default branding provided by Appsilon or customize your own by modifying `_brand.yml` in the root directory.
153+
This file controls the application's metadata, logo, colors, and typography.
154+
Note: `_brand.yml` cannot be empty. All sections below must be defined for the app to work correctly.
155+
156+
#### Metadata
157+
Controls the application's title and credits. You can disable credits by setting `enabled` to `FALSE`:
158+
159+
```yaml
160+
meta:
161+
app_title: "Posit Connect User Metrics"
162+
credits:
163+
enabled: FALSE
164+
```
165+
166+
_* While disabling credits is possible, we encourage you to keep them as a token of appreciation for the developers and contributors. Supporting open-source helps sustain these efforts._
167+
168+
#### Logo
169+
Add your logo to `app/static/images` and set the file name:
170+
171+
```yaml
172+
logo: "your_file.png"
173+
```
174+
175+
#### Colors
176+
Customize the color palette inside the `palette` section. Hex colors are recommended:
177+
178+
```yaml
179+
color:
180+
palette:
181+
white: "#FFFFFF"
182+
mint: "#00CDA3"
183+
blue: "#0099F9"
184+
yellow: "#E8C329"
185+
purple: "#994B9D"
186+
black: "#000000"
187+
gray: "#15354A"
188+
foreground: gray
189+
background: white
190+
primary: blue
191+
```
192+
193+
#### Typography
194+
Define fonts used in the app under the `typography` section. The required keys are `base` and `headings`:
195+
196+
```yaml
197+
typography:
198+
fonts:
199+
- family: Maven Pro
200+
source: google
201+
weight: [400, 500, 600, 700]
202+
style: normal
203+
- family: Roboto
204+
source: google
205+
weight: [400, 500, 600]
206+
style: normal
207+
base:
208+
Roboto
209+
headings:
210+
Maven Pro
211+
```
212+
213+
Refer to the detailed [guide](https://posit-dev.github.io/brand-yml/) for advanced UI customization.
214+
215+
## Disclaimer
216+
Posit Connect usage data is most accurate for applications accessed by authenticated users.
217+
Unauthenticated users cannot be distinguished, so user-level aggregation is not possible in such cases.
218+
219+
Read more: [_Why You Should Use Posit Connect Authentication And How to Set It Up_][rsconnect-auth].
220+
221+
## Troubleshooting
222+
223+
### Posit Connect does not appear to have `CONNECT_SERVER` and `CONNECT_API_KEY` set
224+
Per the [Configuration appendix] in the Posit Connect Admin Guide, these variables are set by default.
225+
However, this behavior can be overridden via [DefaultServerEnv] and [DefaultAPIKeyEnv].
226+
227+
Check with your Posit Connect administrator if that's the case.
228+
229+
### The API connection fails due to a timeout after deploying the User Metrics application
230+
If the connection times out using the default environment variables, the issue may be that the server cannot resolve its own fully qualified domain name.
231+
232+
To fix this, go to the User Metrics [application Vars][User Guide Vars] and set `CONNECT_SERVER` to a local address, e.g.:
233+
```
234+
http://localhost:3939
235+
```
236+
(Note: the scheme in the URL is required by `connectapi::connect()`.)
237+
238+
### There is no usage data for my application
239+
As with environment variables, the [Instrumentation] feature is also configurable.
240+
241+
Confirm with your Posit Connect admin that instrumentation is enabled.
242+
243+
<!-- Links -->
244+
[User Guide Vars]: https://docs.posit.com/connect/user/content-settings/#content-vars
245+
[rsconnect-auth]: https://appsilon.com/why-use-rstudio-connect-authentication/
246+
[Configuration appendix]: https://docs.posit.co/connect/admin/appendix/configuration/
247+
[DefaultServerEnv]: https://docs.posit.co/connect/admin/appendix/configuration/#Applications.DefaultServerEnv
248+
[DefaultAPIKeyEnv]: https://docs.posit.co/connect/admin/appendix/configuration/#Applications.DefaultAPIKeyEnv
249+
[Instrumentation]: https://docs.posit.co/connect/admin/appendix/configuration/#Metrics.Instrumentation
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
meta:
2+
app_title: "Posit Connect User Metrics"
3+
credits:
4+
enabled: TRUE
5+
about:
6+
references:
7+
homepage:
8+
name: "Link to Appsilon"
9+
link: "https://www.appsilon.com"
10+
powered_by:
11+
rhino:
12+
name: "Rhino"
13+
link: "https://appsilon.github.io/rhino/"
14+
img_name: "rhino.png"
15+
desc: "Rhino is an Open-Source Package developed by Appsilon to
16+
help the R community make more professional Shiny Apps. Rhino allows you to
17+
create Shiny apps The Appsilon Way - like a fullstack software engineer.
18+
Apply best software engineering practices, modularize your code,
19+
test it well, make UI beautiful, and think about user adoption
20+
from the very beginning."
21+
summary: "We create, maintain, and develop Shiny applications
22+
for enterprise customers all over the world. Appsilon
23+
provides scalability, security, and modern UI/UX with
24+
custom R packages that native Shiny apps do not provide.
25+
Our team is among the world's foremost experts in R Shiny
26+
and has made a variety of Shiny innovations over the
27+
years. Appsilon is a proud Posit Full Service
28+
Certified Partner."
29+
footer:
30+
text: "Designed and developed with 💙 by"
31+
link:
32+
label: "Appsilon"
33+
url: "https://www.appsilon.com"
34+
35+
logo: "appsilon-logo.png"
36+
37+
color:
38+
palette:
39+
white: "#FFFFFF"
40+
mint: "#00CDA3"
41+
blue: "#0099F9"
42+
yellow: "#E8C329"
43+
purple: "#994B9D"
44+
black: "#000000"
45+
gray: "#15354A"
46+
foreground: gray
47+
background: white
48+
primary: blue
49+
50+
typography:
51+
fonts:
52+
- family: Maven Pro
53+
source: google
54+
weight: [400, 500, 600, 700]
55+
style: normal
56+
- family: Roboto
57+
source: google
58+
weight: [400, 500, 600]
59+
style: normal
60+
base:
61+
Roboto
62+
headings:
63+
Maven Pro
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Rhino / shinyApp entrypoint. Do not edit.
2+
rhino::app()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static_data.rds
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
users:
2+
- this_user_will_not_appear_on_the_app

0 commit comments

Comments
 (0)