Pulling and Displaying Data from a Qualtrics Survey on a Github Pages Website
We have a fake survey about favorite colors and emotions named Test Survey in use in my University of Michigan qualtrics account.
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(qualtRics)
Note that the qualtrics API key is stored in both my local .Renviron file for rendering locally (good for testing), and in a Github Actions repository secret for running as a Github Action. The GHA is directed by a separate .github/workflows/publish.yml file on push (when I push changes to the repo to Github) or on a cron schedule that runs once weekly on Sundays to update the website.
We do our editing of this quarto document, and of the publish.ymldocument on the main branch, and publish to Github Actions from the gh-pages branch.
Let’s use this to read in data the from Test Survey.
Note that we had to change our qualtrics site base url from https://umich.qualtrics.com/ to yul1.qualtrics.com because it was being proxied.
This is per known issue #339 for the qualtrics package.
Note that we use Sys.getenv("API_KEY") to retrieve the specific API key for qualtrics credentials. This works both locally for keys stored in the .Renviron file and remotely for Github Actions repository secrets.
# A tibble: 5 × 4
fav_color anxiety depression happiness
<ord> <dbl> <dbl> <dbl>
1 red 47 74 20
2 blue 16 47 25
3 red 47 15 49
4 blue 23 35 94
5 red 37 10 66
We would not publish the raw data from a survey like this (this one is fake) to a website, as it would be disclosing identifiable information about the participants. Qualtrics is considered HIPAA-compliant.
But we can read in the data and provide ongoing updates/analysis to our colleagues and collaborators with the data. Let’s share a plot or two of the incoming data with our colleagues.
Emotional scores
We have 5 rows of data from 6 participants thus far.