Effective Delivery of Insights

Review


Section Agenda


  • Using Shiny to deliver interactive content
  • Principles of Shiny in production
  • Monitoring production content

Let’s talk Shiny



Whether you’re here
in your Shiny journey:


Photo by Andriyko Podilnyk on Unsplash


Or here:

Photo by Francesco on Unsplash

🧰 Shiny resources

Shiny in production


“But my app runs great on my laptop…”

Two sides to this coin:

  1. Optimize your app
  2. Tune your runtime settings

Shiny in production — Optimize your app


📣 Design principle: Make your app a lightweight presentation layer

Performance workflow:

  • Add logging to app, either basic message statements or use log4r package
  • use shinyloadtest to simulate app performance under load
  • use profvis to profile your app to identify bottlenecks
  • Optimize app (in order of value-add):
    • Move work upstream out of Shiny
    • Make code faster
    • Use caching
    • Use async

🧰 References:

What does our Ferry Delay App need to do?

  • Make requests to our API
  • Receive and display API response

Activity

👉 Activity objective: explore the simply shiny app.

  • Open the project materials/05-shiny-app/05-shiny-app.Rproj
  • Open the file simple_ferry_app/app.R
  • Click Run App and explore the shiny app.

Get a taste for how shiny can be used to create reactive API queries!

Putting the Pieces Together

Our Shiny application does a bit more:

  1. Read in the validated ferry-weather data from database.
  2. Extract ferry station information from ferryfairy package.
  3. Take in user inputs.
  4. Make API queries.
  5. Display API response.
  6. Display a map.
  7. Show average delay times.

Putting the Pieces Together

Our Shiny application does a bit more:

  1. Read in the validated ferry-weather data from database.
  2. Extract ferry station information from ferryfairy package.
  3. Take in user inputs.
  4. Make API queries.
  5. Display API response.
  6. Display a map.
  7. Show average delay times.

📣 This Shiny application does not train a model! Move the computationally heavy stuff outside of your applications!

Activity

Note

👉 Activity objective: explore the simply shiny app.

  • Open the project materials/05-shiny-app/05-shiny-app.Rproj
  • Open the file ferry_delay_app/app.R
  • Supply your API URL to the Shiny App.
  • Deploy to Posit Connect!

Git-Backed Deployment

🤔 What happens when you need to make a change to the Shiny Application?


What if we deployed directly from the GitHub Repo?


Advantages:

  1. Great for collaborative work.
  2. Connect automatically detects changes in repo and rebuilds content.
  3. 📣 All production content should be deployed using git/CI-CD!

Show and Tell

Let’s show you how to deploy a Shiny App (our simple Ferry app) to Posit Connect using Git Backed Deployment.

Shiny on Connect

Runtime settings

Min processes — Keep a process running on the server at all times?

Max processes — Put a bound on the number of processes spawned?

Connections per processA connection = a browser tab. How many connections will share the same process? Call this n

Load factor — Much like min processes, how early do you want to start a new process for that n + 1 connection?

Posit Connect

The Shiny Restaurant Analogy

Let’s say you are the manager of a restaurant, and you need to determine two things:

  1. How many chefs should I hire?
  2. How many customers can I accommodate at once?
  • Chef == process
  • Customer == connection

Posit Connect

The Shiny Restaurant Analogy

A question for you…

What components of our workflow deployed to Posit Connect would benefit from setting Min Processes to > 0?


Monitoring Content

How will I know if people are consuming my content?


🧰 Posit Connect Server API

Posit Connect Server API endpoints

Most endpoints require an API Key, and results will be scoped to the permissions of the key.

Helpful to publishers:

  • List/Update content
  • Get content details
  • Set environment variables
  • Change permissions
  • Manage content tags
  • Manage content custom URL
  • ✨ Content usage ✨

Helpful to admins:

  • 👈 all that
  • Audit logs
  • User and group management
  • Job management


Full documentation: https://docs.posit.co/connect/api/


Accessing the Connect Server API

  • Posit SDKs provide wrappers around curl and HTTP requests for easier interaction:

Remember

Content returned from the Connect Server API will be scoped to the API key provided.


Activity Time!

Activity

👉 Activity objective: Explore the Posit SDK {connectapi} via the Connect Cookbook

  • Browse the Connect Cookbook
  • Open the project materials/06-usage-monitoring/06-usage-monitoring.Rproj
  • Open the file _simple-sdk-example.qmd
  • We’ll work through this file together

Who is Using our App?

https://pub.ferryland.posit.team/r/usage_monitoring/


Optional Activity

Activity

👉 Activity objective: Deploy a ready-made usage dashboard, provided from the Connect Cookbook

  • Return to the project materials/06-usage-monitoring/06-usage-monitoring.Rproj
  • Open the file 06-usage-monitoring.qmd
  • Deploy this file to Connect

How can I know what people are doing in my content?

  • 👉 As we just saw, Connect aggregates higher-level content access information
  • Add tracking or logging to the content itself for user interaction information

Ideas and resources: