-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
110 lines (100 loc) · 3.16 KB
/
index.qmd
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
---
title: 'Lookup: Posit Connect People'
date: "last-modified"
date-format: D MMM YYYY HH:mm
format: html
execute:
echo: false
resource_files:
- R/api.R
---
```{r}
#| label: check-env-vars
#| results: "asis"
required_env_vars <- c("CONNECT_SERVER", "CONNECT_API_KEY")
if (any(Sys.getenv(required_env_vars) == "")) {
cat("One of the following environment variables was not set, so exiting \n\n")
cat(paste("*", required_env_vars, collapse = "\n"), "\n\n")
knitr::knit_exit()
}
```
```{r}
#| label: prepare-workspace
#| include: false
list.files("R", "\\.R$", , TRUE) |> purrr::walk(source)
server_name <- Sys.getenv("CONNECT_SERVER")
people_path <- glue::glue("{server_name}connect/#/people/")
dat <- get_all_users_groups() |>
tidyr::replace_na(list(username = "[No user]", group = "[No group]"))
```
## Purpose
A quick lookup of [users and groups](`r people_path`) on the server `r server_name`. Find [the source on GitHub](https://github.com/The-Strategy-Unit/posit-connect-people/).
## By user
```{r}
#| label: by-user
dat |>
dplyr::select(username, group) |>
dplyr::arrange(tolower(username), tolower(group)) |>
reactable::reactable(
groupBy = "username",
columns = list(
username = reactable::colDef(
filterable = TRUE,
filterInput = function(values, name) {
htmltools::tags$select(
# Set to undefined to clear the filter
onchange = sprintf("Reactable.setFilter('cars-select', '%s', event.target.value || undefined)", name),
# "All" has an empty value to clear the filter, and is the default option
htmltools::tags$option(value = "", "All"),
lapply(unique(values), htmltools::tags$option),
"aria-label" = sprintf("Filter %s", name),
style = "width: 100%; height: 28px;"
)
}
)
)
)
```
## By group
```{r}
#| label: by-group
dat |>
dplyr::select(group, username) |>
dplyr::arrange(tolower(group), tolower(username)) |>
reactable::reactable(
groupBy = "group",
columns = list(
group = reactable::colDef(
filterable = TRUE,
filterInput = function(values, name) {
htmltools::tags$select(
# Set to undefined to clear the filter
onchange = sprintf("Reactable.setFilter('cars-select', '%s', event.target.value || undefined)", name),
# "All" has an empty value to clear the filter, and is the default option
htmltools::tags$option(value = "", "All"),
lapply(unique(values), htmltools::tags$option),
"aria-label" = sprintf("Filter %s", name),
style = "width: 100%; height: 28px;"
)
}
)
)
)
```
## All data
```{r}
#| label: all-data
htmltools::browsable(
htmltools::tagList(
htmltools::tags$button(
"Download CSV",
onclick = "Reactable.downloadDataCSV('data-table', 'posit-connect-people.csv')"
),
reactable::reactable(
dat |> dplyr::arrange(tolower(username), tolower(group)),
filterable = TRUE,
elementId = "data-table",
)
)
)
```