Skip to content

Commit a0bf879

Browse files
authored
Merge pull request #106 from Appsilon/improve-docs
Improve docs
2 parents 960b2a9 + 900fd1b commit a0bf879

16 files changed

+123
-40
lines changed

R/auxiliary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @param timestamp_wrapper string with function to wrap up seconds in database
77
#' query
88
#'
9-
#' @return string with SQL query
9+
#' @return A string with SQL query.
1010
#'
1111
#' @examples
1212
#'

R/data-storage.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ DataStorage <- R6::R6Class( # nolint object_name_linter
2727
#' generated in UTC. By default it should be NULL and determined
2828
#' automatically, but in cases where it should be defined, use `Sys.time()`
2929
#' or `lubridate::now(tzone = "UTC")` to generate it.
30+
#'
31+
#' @return Nothing. This method is called for side effects.
3032

3133
insert = function(
3234
app_name, type, session = NULL, details = NULL, time = NULL

R/plumber-shared.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' communication. It can be NULL on both telemetry and in plumber API to
1313
#' disable this communication feature
1414
#'
15-
#' @return a string that contains an hash to uniquely identify the parameters
15+
#' @return A string that contains an hash to uniquely identify the parameters.
1616
#' @export
1717
#'
1818
#' @examples
@@ -34,7 +34,7 @@ build_token <- function(values, secret = NULL) {
3434
#' @param secret string that contains information that should not be publicly
3535
#' available
3636
#'
37-
#' @return a string with an hash of the secret
37+
#' @return A string with an hash of the secret.
3838
#' @export
3939
#'
4040
#' @examples

R/prepare-admin-panel.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ get_per_day_plot_data <- function(base, per_day) {
120120
#' @param session session object inherited from server function.
121121
#' @param data_storage data_storage instance that will handle all backend read
122122
#' and writes.
123+
#'
124+
#' @keywords internal
123125
prepare_admin_panel_components <- function(
124126
input, output, session, data_storage
125127
) {

R/shiny.telemetry.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#' Shiny app usability logs and statistics
2-
#'
3-
#' @name shiny.telemetry-package
41
#' @importFrom dplyr %>%
52
#' @importFrom rlang .data
63
NULL

R/telemetry.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
107107
#' By default, no navigation is tracked.
108108
#' @param session ShinySession object or NULL to identify the current
109109
#' Shiny session.
110+
#'
111+
#' @return Nothing. This method is called for side effects.
110112

111113
start_session = function(
112114
track_inputs = TRUE,
@@ -185,6 +187,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
185187
#' application so that the function can track and log changes to it.
186188
#' @param session ShinySession object or NULL to identify the current
187189
#' Shiny session.
190+
#'
191+
#' @return Nothing. This method is called for side effects.
188192

189193
log_navigation = function(
190194
input_id, session = shiny::getDefaultReactiveDomain()
@@ -211,6 +215,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
211215
#' @param value string that indicates a value for the navigation
212216
#' @param session ShinySession object or NULL to identify the current
213217
#' Shiny session.
218+
#'
219+
#' @return Nothing. This method is called for side effects.
214220

215221
log_navigation_manual = function(
216222
navigation_id, value, session = shiny::getDefaultReactiveDomain()
@@ -234,6 +240,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
234240
#' @param username string with username from current session
235241
#' @param session ShinySession object or NULL to identify the current
236242
#' Shiny session.
243+
#'
244+
#' @return Nothing. This method is called for side effects.
237245

238246
log_login = function(
239247
username = NULL, session = shiny::getDefaultReactiveDomain()
@@ -253,6 +261,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
253261
#' @param username string with username from current session
254262
#' @param session ShinySession object or NULL to identify the current
255263
#' Shiny session.
264+
#'
265+
#' @return Nothing. This method is called for side effects.
256266

257267
log_logout = function(
258268
username = NULL, session = shiny::getDefaultReactiveDomain()
@@ -274,6 +284,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
274284
#' @param id string that identifies a manual click to the dashboard.
275285
#' @param session ShinySession object or NULL to identify the current
276286
#' Shiny session.
287+
#'
288+
#' @return Nothing. This method is called for side effects.
277289

278290
log_click = function(id, session = shiny::getDefaultReactiveDomain()) {
279291
checkmate::assert_string(id)
@@ -292,6 +304,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
292304
#'
293305
#' @param session ShinySession object or NULL to identify the current
294306
#' Shiny session.
307+
#'
308+
#' @return Nothing. This method is called for side effects.
295309

296310
log_browser_version = function(
297311
session = shiny::getDefaultReactiveDomain()
@@ -332,6 +346,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
332346
#' track the value of the input that are changing. `FALSE` by default.
333347
#' @param session ShinySession object or NULL to identify the current
334348
#' Shiny session.
349+
#'
350+
#' @return Nothing. This method is called for side effects.
335351

336352
log_button = function(
337353
input_id,
@@ -352,6 +368,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
352368
#' package.
353369
#' @param session ShinySession object or NULL to identify the current
354370
#' Shiny session.
371+
#'
372+
#' @return Nothing. This method is called for side effects.
355373

356374
log_all_inputs = function(
357375
track_values = FALSE,
@@ -377,6 +395,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
377395
#' value from JSON format.
378396
#' @param session ShinySession object or NULL to identify the current
379397
#' Shiny session.
398+
#'
399+
#' @return Nothing. This method is called for side effects.
380400

381401
log_input = function(
382402
input_id,
@@ -408,6 +428,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
408428
#' @param value (optional) scalar value or list with the value to register.
409429
#' @param session ShinySession object or NULL to identify the current
410430
#' Shiny session.
431+
#'
432+
#' @return Nothing. This method is called for side effects.
411433

412434
log_input_manual = function(
413435
input_id, value = NULL, session = shiny::getDefaultReactiveDomain()
@@ -434,6 +456,8 @@ Telemetry <- R6::R6Class( # nolint object_name_linter
434456
#' @param details (optional) scalar value or list with the value to register.
435457
#' @param session ShinySession object or NULL to identify the current
436458
#' Shiny session.
459+
#'
460+
#' @return Nothing. This method is called for side effects.
437461

438462
log_custom_event = function(
439463
event_type, details = NULL, session = shiny::getDefaultReactiveDomain()

R/ui_elements.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#' Function that adds telemetry HTML elements to UI
22
#'
33
#' @param id (optional) string with id representing the namespace
4+
#' @return A `shiny.tag` object to be included in the UI of a Shiny app.
45
#'
56
#' @export
67
use_telemetry <- function(id = "") {

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,45 @@
88
[![downloads total](https://cranlogs.r-pkg.org/badges/grand-total/shiny.telemetry)](https://CRAN.R-project.org/package=shiny.telemetry)
99
[![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://opensource.org/license/lgpl-3-0/)
1010

11-
The `shiny.telemetry` R package tracks events occurring on a user session, such as input changes and session duration, and stores them in a local or remote database.
11+
The `shiny.telemetry` R package tracks events occurring on a user session,
12+
such as input changes and session duration, and stores them in a local or remote database.
1213

13-
It provides developers with the tools to help understand how users interact with Shiny dashboards and answer questions such as: which tabs/pages are more often visited, which inputs users are changing, what is the average length of a session, etc.
14+
It provides developers with the tools to help understand how users interact with Shiny dashboards
15+
and answer questions such as: which tabs/pages are more often visited,
16+
which inputs users are changing, what is the average length of a session, etc.
1417

1518
## Install
1619

1720
The `shiny.telemetry` package can be installed from GitHub by using the remotes package:
1821

1922
```R
20-
remotes::install_github("Appsilon/shiny.telemetry")
23+
remotes::install_github("Appsilon/shiny.telemetry", dependencies = TRUE)
2124
```
2225

26+
With `dependencies = TRUE` the suggested packages (required to run some examples)
27+
will be installed in addition to mandatory dependencies.
28+
2329
## How to use in a Shiny Dashboard?
2430

25-
`shiny.telemetry` allows for a minimal setup with only 3 commands that can track some information about the session:
31+
`shiny.telemetry` allows for a minimal setup with only 3 commands
32+
that can track some information about the session:
2633

2734
* When session starts and ends
2835
* The browser version used by the client
2936
* Changes in the inputs _(doesn't track values by default)_
3037

31-
The code below runs a minimal example of a shiny application that uses `shiny.telemetry`.
32-
In this example, this package will keep the session information and all changes to the `numericInput`.
38+
The code below runs a minimal example of a Shiny application that uses `shiny.telemetry`.
39+
The package will keep track of the session information and all changes to the `numericInput`.
3340

34-
ℹ️ _note_: When using the dashboard nothing is happening from the user's perspective as all operation run in the background _(either in the server or in Javascript)_.
41+
_Note_: When using the dashboard nothing is happening from the user's perspective
42+
as all operation run in the background _(either in the server or in Javascript)_.
3543

36-
```R
44+
```r
3745
library(shiny)
3846
library(shiny.telemetry)
47+
3948
telemetry <- Telemetry$new() # 1. Initialize telemetry with default options
49+
4050
shinyApp(
4151
ui = fluidPage(
4252
use_telemetry(), # 2. Add necessary Javascript to Shiny
@@ -53,45 +63,57 @@ shinyApp(
5363
When inspecting the code above, we can breakdown the 3 lines of code by:
5464

5565
1. Global `Telemetry` object that is used across the different sessions
56-
2. Add necessary Javascript to the UI by calling `use_telemetry()`. It is used to track browser version.
57-
3. Initialize the session-specific tracking by calling method `start_session()` of the `Telemetry` object
66+
2. Add necessary Javascript to the UI by calling `use_telemetry()`.
67+
It is used to track browser version.
68+
3. Initialize the session-specific tracking
69+
by calling method `start_session()` of the `Telemetry` object.
5870

5971
## How to access the data?
6072

6173
The developers and administrators of the dashboard can access the data that is gathered by `shiny.telemetry` via a Telemetry object or directly from `DataStorage` via the appropriate provider.
6274

6375
```R
64-
# After running the instrumented
76+
# After running the instrumented app
6577
shiny.telemetry::Telemetry$new()$data_storage$read_events("2020-01-01", "2050-01-01")
6678

67-
# default provider and path for Telemetry$new()
79+
# Default provider and path for Telemetry$new()
6880
shiny.telemetry::DataStorageSQLite$new(db_path = "telemetry.sqlite")$read_events("2020-01-01", "2050-01-01")
6981
```
7082

71-
The package has an analytics sample dashboard to help access the data. It is located at `inst/examples/app/analytics` and it should be modified so that it references the correct `DataStorage` provider and configuration.
83+
The package includes an analytics dashboard to view the data.
84+
It is located at `inst/examples/app/analytics` and it should be modified
85+
so that it references the correct `DataStorage` provider and configuration.
7286

7387
## Data providers
7488

75-
There are 3 different types of data providers that can range from local filesystem storage to a remote plumber REST API instance.
89+
There are 3 different types of data providers
90+
that can range from local filesystem storage to a remote Plumber REST API instance.
7691

77-
* SQLite using `DataStorageSQLite` class
78-
* Logfile using `DataStorageLogFile` class
79-
* MariaDB using `DataStorageMariaDB` class
80-
* PostgreSQL using `DataStoragePostgreSQL` class
92+
* Local file:
93+
* SQLite using `DataStorageSQLite` class
94+
* Logfile using `DataStorageLogFile` class
95+
* Remote SQL database:
96+
* MariaDB using `DataStorageMariaDB` class
97+
* PostgreSQL using `DataStoragePostgreSQL` class
8198
* Plumber REST API using `DataStoragePlumber` class
82-
* In turn, the Plumber data provider will use one of the other classes above as the method of data storage.
99+
* In turn, the Plumber data provider will use one of the other classes above
100+
as the method of data storage.
83101

84-
The setup for plumber requires a valid Plumber instance running on the network and the communication can be protected. See Plumber deployment documentation for more information.
102+
The setup for plumber requires a valid Plumber instance running on the network
103+
and the communication can be protected.
104+
See Plumber deployment documentation for more information.
85105

86106
## Debugging the Telemetry calls
87107

88-
The package uses the `logger` package internally with the `shiny.telemetry` namespace. To debug the `shiny.telemetry` calls in the dashboard, change the threshold of this namespace to `DEBUG`.
108+
The package uses the `logger` package internally with the `shiny.telemetry` namespace.
109+
To debug the `shiny.telemetry` calls in the dashboard,
110+
change the threshold of this namespace to `DEBUG`:
89111

90-
```R
112+
```r
91113
logger::log_threshold("DEBUG", namespace = "shiny.telemetry")
92114
```
93115

94-
ℹ️ _note_: This command can be run before the Shiny call or by adding it to the `.Rprofile`.
116+
_note_: This command can be run before the Shiny call or by adding it to the `.Rprofile`.
95117

96118
## Appsilon
97119

man/DataStorage.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)