Jon Harmon | {shinyslack}: Connecting Slack Teams to Shiny Apps | Posit (2022)
videoimage: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
Hi, my name is John Harmon. I run the R4DS online learning community. Our community operates primarily through a Slack team, and we invite R learners at all skill levels to join us at r4ds.io slash join. Among other things, we host book clubs for R-related books. Whenever we start a new cohort for one of the book clubs, we need to find a time that works for as many of the people interested in reading the book as we can.
We used to use a generic free online app for everyone to sign up. Everyone would type in their name, choose their available times and days, and then set a password in case they wanted to edit their selections. Sometimes people would sign up twice, not remembering that John who was signed up already was them. At least one time, someone had a typo in their name, so when they came back to change their available hours, it counted as a new person. And of course, sometimes we legitimately had multiple people with the same name signing up, so I didn't have any way to sort out who was who and how many duplicates we had. And even when everything went smoothly, I didn't have an easy way to connect the information in that app to their Slack user, so I couldn't contact people directly to let them know that a cohort was being created at a time they'd chosen.
Building shinyslack
So I figured we already all have logins to the R4DS Slack. What if we made our own app in Shiny and then connected that to the Slack API? Then the app could talk to our Slack and connect each user to their identity on R4DS. I posted the idea on our Slack, and one of our users, Priyanka Gagnija, volunteered to make the initial app minus the login, and then I focused on the login part. I'd already done some work with Yanni CD on his Slack teams package, which allows you to talk to Slack through R. You can find that and Yanni's whole Slackverse family of packages on GitHub at YanniCD.
My goal was to take what I did there with interactive Slack authorization, make it work in Shiny, and then wrap that up into an easy-to-use package. So this is what that looks like. If you aren't already logged in, it asks you to log in using Slack. From that initial screen, you're taken to Slack's permission screen to connect to your Slack account, and then it returns you to the Shiny app. Here we just use the connection to identify the user, but I have another app where we use it to make sure the user has permission to see certain messages, and I'm working on one that will help users ask better questions and then post those questions as them.
Using the package
So it works. Now let's see how I did on the easy-to-use part of the goal. You can install this from GitHub at R4DS slash Shiny Slack. This is one of the ways we can launch a normal Shiny app. We define a UI, define a server function, and wrap them in Shiny's Shiny app function. Now we'll use Shiny Slack to add a Slack login to that app. We replace Shiny's Shiny app with Shiny Slack's Shiny Slack app. We also need to give it the code that identifies our Slack team. And that's it. Well, kinda.
And that's it. Well, kinda.
So you probably want to deploy your app to something like shinyapps.io, not just run the app locally. And to do that, you'll need your own Slack app that has permission to send people to apps hosted on your Shiny apps account. When I first started working on this, setting up the Slack side of things was really complicated. I was kind of dreading explaining this part. I mean, I just did that thing showing you how easy it is to set up the Shiny side of this, and this part was going to ruin that. But then something magical happened. Slack added an option to create a Slack app from something called a manifest. So I added a function over in Slack teams, create custom app to make that easy. There's a vignette explaining it, but basically you call create custom app with a couple arguments and copy paste the result into Slack's app creation form. And with that, you can wrap your Shiny app with Shiny Slack and integrate it with your Slack team.
If you'd like to learn more, stop by the R4DS Slack at r4ds.io slash join. We're putting together a new club where we walk through side projects like this, so you can learn all about how this works under the hood over there.
