Git Product home page Git Product logo

connect-usage's Introduction

RStudio Connect Usage Data

This repository illustrates several examples for getting started with the RStudio Connect usage data. The examples:

The examples are generated using the RStudio Connect Server API. The API and data collection are both available as of RStudio Connect 1.7.0. The API contains data to help answer questions like:

  • What content is most visited?
  • Who is visiting my content?
  • What reports are most common?
  • Has viewership increased over time?
  • Did my CEO actually visit this app?

A data science team’s time is precious, this data will help you focus and justify your efforts.

Basic example

The following code should work as-is if copied into your R session. NOTE that it uses the connectapi package, which can be installed from GitHub with remotes::install_github("rstudio/connectapi"). You just need to replace the server name, and have your API key ready.

## ACTION REQUIRED: Change the server URL below to your server's URL
Sys.setenv("CONNECT_SERVER"  = "https://connect.example.com/rsc") 
## ACTION REQUIRED: Make sure to have your API key ready
Sys.setenv("CONNECT_API_KEY" = rstudioapi::askForPassword("Enter Connect Token:")) 

This will use the get_usage_shiny() function to pull the latest activity of the Shiny apps you are allowed to see within your server.

library(ggplot2)
library(dplyr)
library(connectapi)

client <- connect()

# Get and clean the Shiny usage data
shiny_rsc <- get_usage_shiny(
  client,
  from = lubridate::today() - lubridate::ddays(7), 
  limit = Inf
  ) %>%
  filter(!is.na(ended)) %>%
  mutate(session_duration = ended - started)

glimpse(shiny_rsc)
## Rows: 336
## Columns: 6
## $ content_guid     <chr> "dad2ac84-2450-4275-b26e-8e0d9d741100", "6f69884b-562…
## $ user_guid        <chr> NA, NA, NA, NA, NA, NA, NA, "7defcf1b-69f6-4bc5-8b52-…
## $ started          <dttm> 2022-02-23 01:54:12, 2022-02-23 03:17:46, 2022-02-23…
## $ ended            <dttm> 2022-02-23 01:54:45, 2022-02-23 03:19:25, 2022-02-23…
## $ data_version     <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ session_duration <drtn> 33 secs, 99 secs, 3685 secs, 61 secs, 59 secs, 51 se…

The identifiers used for the content in RStudio Connect are GUIDs. We can retrieve content names using the API. The API handles only one GUID at a time, so purrr’s map_dfr() is used to iterate through all of the unique GUIDs in order to get every Shiny app’s title.

# Get the title of each Shiny app
shiny_rsc_titles <- shiny_rsc %>%
  count(content_guid) %>% 
  pull(content_guid) %>%
  purrr::map_dfr(
    ~tibble(content_guid = .x, content_name = content_title(client, .x))
    )

glimpse(shiny_rsc_titles)
## Rows: 40
## Columns: 2
## $ content_guid <chr> "0287f7d9-4d55-4813-8852-680f54beaad1", "06484fbb-f686-42…
## $ content_name <chr> "Example Palmer Penguins Shiny Dashboard", "Classroom Stu…

The new shiny_rsc_titles table, and the shiny_rsc can be joined to return the “user readable” title. Using standard dplyr and ggplot2 functions, we can now determine things such as the top 10 apps based on how long their average sessions are.

# Calculate the average session duration and sort
app_sessions <- shiny_rsc %>%
  inner_join(shiny_rsc_titles, by = "content_guid") %>%
  group_by(content_name) %>%
  summarise(avg_session = mean(session_duration)) %>%
  ungroup() %>%
  arrange(desc(avg_session)) %>%
  head(10)
  
# Plot the top 10 used content
app_sessions %>%
  ggplot(aes(content_name, avg_session)) +
  geom_col() +
  scale_y_continuous() +
  geom_text(aes(y = (avg_session + 200), label = round(avg_session)), size = 3) +
  coord_flip() +
  theme_bw() +
  labs(
    title = "RStudio Connect - Top 10", 
    subtitle = "Shiny Apps", 
    x = "", 
    y = "Average session time (seconds)"
    )

Learn more about programmatic deployments, calling the server API, and custom emails here.

connect-usage's People

Contributors

colearendt avatar edgararuiz-zz avatar eheinzen avatar jvail1 avatar kmasiello avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

connect-usage's Issues

Add an example admin app

An example admin app that does the following would be useful:

  • content by number of bundles
  • content by number of renderings
  • some manner of disk usage monitoring? Do we store size of things?

Unable to Knit or Publish on RS Connect

I am interested in at least trying to get this to run the example in this repo (rsc-usage.Rmd) with the scheduler in RS Connect. However, I have issues deploying the content to RS Connect from RS Server Pro.

When I deploy to RS Connect, I see the following:

The CONNECT_SERVER and CONNECT_API_KEY environment variables are required in order for this report to pull usage data.

Please define these variables and then re-run the report.

Of course, this is after adding the environment variables in RS Connect.

If I try to Knit the document, it fails.

output file: rsc-usage.knit.md

/usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS rsc-usage.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output rsc-usage.html --email-obfuscation none --self-contained --standalone --section-divs --template /opt/R/3.6.2/lib/R/library/flexdashboard/rmarkdown/templates/flex_dashboard/resources/default.html --variable 'theme:cosmo' --include-in-header /tmp/RtmpGluOsU/rmarkdown-str9375782c95ff.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --lua-filter /opt/R/3.6.2/lib/R/library/rmarkdown/rmd/lua/pagebreak.lua --lua-filter /opt/R/3.6.2/lib/R/library/rmarkdown/rmd/lua/latex-div.lua --include-in-header /tmp/RtmpGluOsU/file937524480922html --include-before-body /tmp/RtmpGluOsU/file93753c40b650.html --highlight-style pygments --include-before-body /tmp/RtmpGluOsU/file9375432d15e8.html --include-after-body /tmp/RtmpGluOsU/file9375255c61be.html --css styles.css
pandoc: /tmp/RtmpGluOsU/email93758ba12e6_files/figure-html/add_plot-1.mb.png: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1

If I just run the cells manually, they all work. I can even see the email report preview when I run the last cell. So the code runs, but there's some issue with deployment that I can't pin point.

Any thoughts?

connectAnalytics package demo

Hi all,

I created an R package (connectAnalytics) that ships a shiny application that can be used to track Usage and User information on a RStudio Connect server using the connectapi and golem packages. The package is not totally finished yet as I still need to write unit tests and maybe add a few things. However, I think that the application and package have the basic structure of what I was hoping for. The one thing that I am missing is a demo application that is hosted and pointed at a dummy version of RStudio Connect. I am able to run the app against my companies instance of Connect but I am not able to share this with anyone outside of the company.

My question is whether or not you all would be willing to host the application similarly to how the usage .Rmd file is hosted in this repo, pointing it at the same (or a similar) Connect instance. The README of the github page linked above has some info about the options available for deploying the app. It is worth noting again here that, if you are willing to host it (or point me to a connect server that I can point the app to and host myself), it would be best if the api key was for a system admin as that would allow viewers to see the "Admin" tab as well as the user's "Usage" tab so that they can see the full functionality. Additionally, if the key is for an admin, there is a feature that the user can set whether to allow people viewing the app to switch which user they are looking at which can be handy if this is something managers would like to track for their employees but the manager is not a admin on the server themselves.

In addition to that, I am open to any suggestions about improving the application. One suggestion from @colearendt was to make all the graphs reactive to each other. I have not been able to implement that but will continue thinking about how to best accomplish it. Any other suggestions or issues are greatly appreciated!

Thanks for making such a great product!

Connectapi package provides wrong timezone

Hi all,

I am currently working with the connectapi package and found out a bug concerning the timezones.
RStudio Connect saves timestamps in UTC format, my local timezone is CEST.

When I am now calling the connectapi package with a function like get_usage_shiny(), the connectapi package provides the UTC timestamps as wrong CEST timestamps.

For example:
"2020-09-23 06:03:08 UTC" is provided as "2020-09-23 06:03:08 CEST".

For comparison I called the RStudio Connect connectapi directly and the result is the correct timestamp:
"2020-09-23 06:03:08 UTC"

I attached a pdf RMarkdown output, with reproducible code, to emphasize the problem.

I am aware of the fact, that I could just transform the date in the backend, but I really appreciate the connectapi package and would like to contribute to help make it better.

wrong_timezone.pdf

how to get users only for limited number of apps?

Hello team,

I am trying to get the users for the limited number of apps not all of them. you get get_users function but do not have more parameters, to filter out only 22 apps rather than all of them from my rstudioconnect.

This is an example I have:

shiny_rsc <- get_usage_shiny(
  client,
  content_guid = '1095e595-c1ef-4208-82e5-3ada982facf6|e2c258d4-bc8b-4603-967f-6d8de4d71f87|128ff6d9-ef38-472a-974b-b16e7c47927b|b3a52251-8116-4db3-bd71-64d17fd0be61|5fccc9b3-4faa-4d22-bde3-d9c9fb3f0a04|a3bc70e1-10dc-421d-b28a-1b07dba3ab99|c56cbf6c-77ff-43dd-b3d5-4f68c21079cf|08cea12b-4b26-4294-9297-873ecb4ce389|d793eaa8-ebfe-4214-8228-d8e9822a442d|c90112dd-b70c-4308-a3a1-092d94a989ec|877854e6-4ed4-46e4-a6e4-d8bca4d8b7f2|5f8d0573-7db4-474a-b729-6ebf978d5b47|a2ec3ffb-0fe4-484c-8872-0ba859f9ff11|f2f1a502-e208-4c4a-ac64-2789f7d4ce37|cdb37cc5-ecb5-4118-91cd-0c98fddbae74|bb8e7d45-6d44-4221-b2b2-4bc97eb70bae|0ab807d2-ce61-4fc1-8f64-6d2a68bb6a82|21ebe383-d537-4803-a828-b32224a3ea72|80294881-5efe-4c3e-9cbb-3d6d942263e0|364d223f-e9e5-42f3-82a7-83a032827535|10b8935b-abda-4b7d-abed-b2c2e0bfc7cc|b1e2f2c8-25fe-45e0-95b9-8daac757ec85|91ee4a6a-0281-407e-9064-cd79a6515671|b1e2f2c8-25fe-45e0-95b9-8daac757ec85|0ab807d2-ce61-4fc1-8f64-6d2a68bb6a82',
  from = lubridate::today() - lubridate::ddays(30),
  limit = Inf) %>%
  filter(!is.na(ended)) %>%
  mutate(session_duration = as.numeric(difftime(ended, started, unit = c("sec"))))

Then I take the app names with this code:

shiny_rsc_titles <- shiny_rsc %>%
  count(content_guid) %>%
  pull(content_guid) %>%
  purrr::map_dfr(
    ~tibble(content_guid = .x, content_name = content_title(client, .x))
  ) %>%
  dplyr::left_join(shiny_rsc, shiny_rsc_titles, by = "content_guid")

And based now tried this code to get the users linked to my shiny_rsc_titles with this code:

users <- shiny_rsc_titles %>%
  pull(content_guid) %>%
  purrr::map_dfr(
    ~tibble(content_guid = .x, users = get_users(client, .x)) 
    ) %>%
    dplyr::left_join(shiny_rsc_titles, users, by = "content_guid")

Am I doing the right thing in order to get the users for the apps I am interested rather than all the apps?

I get an error :


Error in sprintf("v1/users?page_number=%d&page_size=%d", page_number,  : 
  invalid format '%d'; use format %s for character objects

Please help?

Move `master` branch to `main`

The master branch of this repository will soon be renamed to main, as part of a coordinated change across several GitHub organizations (including, but not limited to: tidyverse, r-lib, tidymodels, and sol-eng). We anticipate this will happen by the end of September 2021.

That will be preceded by a release of the usethis package, which will gain some functionality around detecting and adapting to a renamed default branch. There will also be a blog post at the time of this master --> main change.

The purpose of this issue is to:

  • Help us firm up the list of targetted repositories
  • Make sure all maintainers are aware of what's coming
  • Give us an issue to close when the job is done
  • Give us a place to put advice for collaborators re: how to adapt

message id: euphoric_snowdog

Unable to fetch the data from RS Connect after deploying the app

I have created one app with connectapi r package and its working locally with SERVER and KEY. I deployed same app on RS connect server and added the environment variables. But app is unable to fetch the data with connect api for deployed application.

When I deployed the app on RS Connect , I can see the following:

Warning: Error in curl::curl_fetch_memory: Peer certification cannot be authenticated with given CA certificates: [example.server.com] SSL certificate problem: self signed certificate in certificate chain

This above error is from RS connect deployed application log.

If I run the same app with environment variable locally the app is working. I can able to connect to RS connect server and fetch the data. I am facing the issues while deploying the same app on RS connect same server.

Any suggestions?

Pre-flight check confuses users

Hey folks,

I was working through this example with a customer yesterday and the preflight check caused a lot of confusion for them. I think the HTML print message when it fails is useful when rendered. For someone trying to work through the code, however, it is confusing. Perhaps we can either simplify this, or add it to the readme, that would be helpful.

```{r preflight_check, results='asis', include=TRUE}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.