Created
July 9, 2024 14:57
-
-
Save kellobri/a2cfe49a10745494d716f853fee9b63f to your computer and use it in GitHub Desktop.
Posit Connect Public Access Analysis for Interactive Content with Usage Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Public Access Content Analysis with Usage Data" | |
output: html_document | |
date: "2024-07-09" | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
``` | |
## Public Access Content by Type (Interactive Only) | |
```{r} | |
# Use the connectapi R package with a .Renviron file as described here: https://pkgs.rstudio.com/connectapi/index.html | |
# To get complete data, use a Connect Administrator API key | |
library(connectapi) | |
client <- connect() | |
``` | |
```{r} | |
library(dplyr) | |
# Start by pulling everything published to the server | |
all_content <- get_content(client, limit = Inf) | |
# Filter this table to look at only the content with access_type "all" for "anyone - no login required" | |
public_content <- all_content %>% | |
filter(access_type == "all") | |
#app_modes_used <- public_content %>% | |
# distinct(app_mode) | |
``` | |
The list of all possible interactive "App Modes" supported by Connect can be found in the API reference guide. | |
As of Posit Connect 2024.06.0, the interactive `app_modes` are as follows: | |
- rmd-shiny | |
- python-shiny | |
- shiny | |
- api | |
- python-fastapi | |
- python-api | |
- python-bokeh | |
- python-streamlit | |
- python-dash | |
- quarto-shiny | |
- tensorflow-saved-model | |
- jupyter-voila | |
Generate a summary table of the app_modes in use on your Connect server which have also been set to the "anyone - no login required" sharing setting: | |
```{r} | |
# Current list of interactive app_modes | |
interactives <- c( | |
"rmd-shiny", | |
"python-shiny", | |
"shiny", | |
"api", | |
"python-fastapi", | |
"python-api", | |
"python-bokeh", | |
"python-streamlit", | |
"python-dash", | |
"quarto-shiny", | |
"tensorflow-saved-model", | |
"jupyter-voila" | |
) | |
interactive_public_content <- public_content %>% | |
filter(app_mode %in% interactives) | |
summary_public_interactive <- interactive_public_content %>% | |
count(app_mode) | |
print(summary_public_interactive) | |
``` | |
## Usage Data | |
Now that you know how many content items are "public" on your server, use the following code snippets to augment that data with usage (instrumentation data) from the last 60 days. Note that Shiny content and Non-Shiny content require different API requests because Shiny captures "sessions" and "session duration", whereas all other types of content only capture "visits". | |
### Non-Shiny Public Interactive Content Accessed in the Last 60 Days | |
```{r} | |
library(lubridate) | |
report_from <- lubridate::today() - lubridate::ddays(60) | |
content <- get_usage_static( | |
client, | |
from = report_from, | |
limit = Inf | |
) %>% | |
rename(guid = content_guid) | |
interactive_content_usage <- content %>% | |
inner_join(interactive_public_content, by = "guid") %>% | |
group_by(guid) %>% | |
summarize(visits = n()) %>% | |
arrange(desc(visits)) | |
print(interactive_content_usage) | |
``` | |
### Shiny Public Interactive Content Accessed in the Last 60 Days | |
```{r} | |
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)) %>% | |
rename(guid = content_guid) | |
interactive_shiny_usage <- shiny %>% | |
inner_join(interactive_public_content, by = "guid") %>% | |
group_by(guid) %>% | |
summarize(sessions = n()) %>% | |
arrange(desc(sessions)) | |
print(interactive_shiny_usage) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment