Track Shiny App User Activity With the RStudio Connect Server API
This article is originally published at https://www.rstudio.com/blog/
Data scientists spend a lot of time creating apps, dashboards, and reports. All of this effort is often hampered by siloed workflows between coworkers and across teams, which leads to delays in presenting your insights to stakeholders and clients.
After all that time and effort, are you even sure what you’re sharing is relevant to your audience? You may start to wonder: who looked at this recently? What content is most popular? Having the numbers to back up your work can help you determine your next move and justify your efforts to your stakeholders.
RStudio Connect is designed to help you share and understand your data products in real-time. Connect is RStudio’s enterprise publishing platform for data science products like R Markdown documents, Shiny apps, Flask APIs, and more. Using the RStudio Connect Server API, you can extend Connect to see advanced usage metrics to answer important questions and focus your data science work.
Cole Arendt from RStudio presented on the topic during a YouTube Live event. Watch the webinar here:
Collecting Instrumentation Data From RStudio Connect
RStudio Connect automatically records “instrumentation data”, or data from when users visit your server. As a publisher or administrator, you have access to these data: who logged in, when they logged in, what they looked at, and how long they spent on that piece of content.
Here is an example of Shiny instrumentation data from Connect:
You can use instrumentation data to answer questions like:
- How many Shiny apps are on this server?
- Who looked at this app recently and for how long?
- Which users have access to which app?
- Is viewership increasing?
With this information, you can track progress against your goals and efficiently set up your next steps. This will cut down on overhead and free up time to allocate towards other efforts.
If you are interested in ways of boosting viewership, you can create a custom gallery of your content using the connectwidgets package. This makes it easy for your audience to discover your work without scrolling through your entire Connect server. Have some restricted apps in your gallery? The permissions feature directs non-authenticated viewers to request access. Read more about RStudio Connect’s content creation features.
Extending Connect With the RStudio Connect Server API
The RStudio Connect Server API provides easy access to your server’s instrumentation data. With the R and Python clients, you can load your server’s instrumentation data into your IDE.
To install connectapi in R, run the below:
remotes::install_github('rstudio/connectapi')
Create a client:
library(connectapi)
client <- connect(
server = 'https://connect.example.com',
api_key = '<SUPER SECRET API KEY>'
)
# If your server is defined by your environment variables, you can just run:
client <- connect()
Once you set up your client, you can use it to interact with RStudio Connect. Say you want to retrieve the instrumentation data from all of your Shiny apps:
usage_shiny <- get_usage_shiny(client)
This results in a data frame with the instrumentation data mentioned above.
Creating a Report With Connect Server API Data
Once you have access to the Connect server data, you can make custom informative reports for your stakeholders. For example, this flexdashboard shows the most popular Shiny applications and static content from RStudio’s demo server:
Since this dashboard is built with R Markdown, you can schedule emails with RStudio Connect and the blastula package. Send an email to your team anytime the dashboard is refreshed. Find out how on the Solutions website.
Need something more interactive? You can create a Shiny app for users to explore the data in real-time. This one shows the most popular apps and most active viewers over time.
Want to try these out with your RStudio Connect server? You can download the code from our Github repository, add your environment variables, and display your own data.
Learn More
With the RStudio Connect API, you can access data that helps quantify your work’s reach and make content more relevant to your stakeholders.
- Watch the full webinar on YouTube and review Cole’s slides.
- Check out the RStudio Connect Server API Cookbook for useful recipes when accessing your usage data.
- Read the Solutions Engineering team’s documentation on how to create the dashboard shown above and a showcase of different types of Connect API reports.
- Access the R client and Python client for the Connect Server API.
Want to make the RStudio Connect Server API bigger and better? We have a variety of spots to check out.
- Join the discussion on RStudio Community.
- Contribute to open-source packages and tools. We welcome pull requests, examples, feature requests, issues, and comments.
Thanks for visiting r-craft.org
This article is originally published at https://www.rstudio.com/blog/
Please visit source website for post related comments.