
Katie Masiello || Build a Codenames app using {pins} and Shiny! || RStudio
00:00 Introduction 00:05 Project outline 03:56 Create a codename generator (using RMarkdown) 09:35 Publish to RStudio Connect 10:38 Create a Shiny app 18:15 A little bit of troubleshooting 18:18 Ta-da! Learn more about the pins package here: https://pins.rstudio.com/ Learn more about Shiny here: https://shiny.rstudio.com/ And learn more about RStudio Connect here: https://www.rstudio.com/products/connect/ Got questions? The RStudio Community site is a great place to get assistance: https://community.rstudio.com/ Content: Katie Masiello (@katieontheridge) Animation, motion design, and editing: Jesse Mostipak (@kierisi) Theme song: Contrarian by Blue Dot Sessions (https://app.sessions.blue/browse/track/64281)
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
So when I'm thinking through a project like this I kind of want to map out in my head or on a piece of paper sort of what I want to do and where I want things to go. So in this case right we have this need to adopt a persona every day with a secret codename and so we can use pins for that kind of as a backbone for this because we might end up deciding that we want for one a Shiny app right that we can log into and we can see what our what our codename is for the day we might want a daily email that tells us what our codename is delivered to our box or we could even go so far as you know let's let's make a slack bot right that runs and it sends me a slack message and tells me what my name is these kinds of things right so so we might have need for this information of what our daily generated codename is going to be delivered in multiple ways and so that's why I think using a pin for this information of what's my real name and what's my codename gonna be so we're gonna start off right and we're gonna have this pin we're gonna have our our username right you have to forget my handwriting and our codename right and so this is just gonna be data right what's this gonna be so we're gonna take this you'll love this we're just gonna stick this thing on a pin right use this here how are we gonna get this information right we want this to be updated on a daily basis and so one of the best ways that we can do this let's make a little script right and this is gonna be generate that's what that says generate pen this is gonna be a RMarkdown document and we're just gonna schedule this little puppy right we'll publish this on the connect we'll schedule it so every single day my RMarkdown document is going to take my list of users take a list of generated code names smush them together and stick it into a pen so we'll do that stick this up here and then from this right we have other things that we can do we can make a Shiny app right you are right here's your Shiny app right and you can do Shiny right stick this here you could do other things right you could have a slack bot you could have an email right and that email you know we would generate that we generate that with an RMarkdown document and blastula for example right um have connect send that on our behalf via RMarkdown the slack bot as well we can generate that with a script put that up in RMarkdown so all of these things are using our pen so these are all the little elements that we're gonna put into place you might go back to this beginning to say well okay how are we gonna get our get our usernames and where are we gonna pull this from just what happens I have another pin just sitting around that does have all of the usernames for folks that are on our connect server so I've already got this as a pen so what a fun project we're actually gonna start with data that's penned bring it into an RMarkdown create another pen and then use it for downstream assets sound fun
Creating the codename generator
all right so let's get cooking we'll start with this RMarkdown document is going to be our pin generator right so we need to pull in our usernames so generate all right clean all of this stuff up and so what do we want to do first we need to get some libraries in pens we're gonna need fire my favorite I need to spell it correctly my favorite little package for generating code names one little one called IDs okay so this should be all that we need first we're gonna go grab the user data information that we have so we're gonna use pens define a board board RSC connect and run that so yep we've got our board defined and let's get our users send board and read into my board and it is what is it user users user I think it's user let's try it hey it seemed to work okay awesome we've got user information a hundred and sixty six users cool all right so we can take this we don't need any of this other stuff what I want to do is just get username and assign a code name and my ultimate goal for this Shiny app is I want the user to log in pull up the Shiny app and I want the Shiny app to know who that user is and then tell them record name so we're gonna use for that app just kind of charting the course here we're gonna use this ability to do session dollar sign user on the app so that we can distinguish who is who and now let's make up some code names.
So let's make a table here code names let's take users and we just want username and we want to mutate let's stick a code name equals let's see I gotta go by memory yeah let's play around a minute with this IDs function IDs adjective animal okay animal n equals one let's do let's just for kicks let's spit out five one adjective to make case and let's just see if we get ah cool oh no I don't like some of those but all right run this a couple of times and we've got some good stuff okay so this is what we want to do we want to use additive animal code name equals adjective animal and let's see some of these can be a little bit wild so let's put I remember from other playing with this package it gets a little some of the names get to be a little bit excessive if you don't put a maximum length on it so let's see what we get that's not good everybody's a frugal people we need to do let's do this whoops and equals number of rows game users is that gonna get me so I have unique names yes doughy that's concave flamingo all right now we are cooking every time we run this it's going to cook up new names so I want to make it unique for every day so let's let's set the seed and does this work as numeric
all right set the seed code names do we get the same ah I didn't set the seed twice lazy mute perfect okay we have stable code names and now all we need to do I'm not talking to my code very well create code name this is obvious table and now we need to pin it so we're gonna take our board type that into pin right and we're going to put code names to it
Publishing to RStudio Connect
I'm gonna publish this as well so we can put it on a schedule so let's publish this little we're gonna publish this here we go we are deployed all right so we've got our pen generator or writing depends now let's schedule this otherwise we're gonna end up with the same code name every day so let's run this and yeah we should probably run this just a little after midnight every day that sounds good so now this is gonna run it's gonna run on a daily basis so here's our graphic of where we are it's going to run and every day update this pin for us.
here we go we are deployed all right so we've got our pen generator or writing depends now let's schedule this otherwise we're gonna end up with the same code name every day.
Building the Shiny app
So so we wanted to make this Shiny app right that's going to tell us every day what our code name is I am NOT the world's most elegant Shiny developer but I will get by love a good clean slate okay so for our Shiny app we're gonna need Shiny let's see are we gonna need anything else or of course we're gonna need pens again can't spell and then all right so what do we want this to do first we're gonna want to bring in bring in our code name table so we're gonna do that board this is gonna look familiar right board equals RS connect and code names equals read board and then what we call it what did we call it we call it code names I think so all right cross your fingers
good names there we are you lazy newt okay so where were we we need to bring it all in and have a nice little greeting so let's do like on our main panel let's give output and this would just be our greeting all right and then what is our greeting it is going to be something along the lines of render text and then let's do secret agent and then we need to put in the username however we determine it to be all right we need to figure out what our username is going to be so how do we know the username and so two things right we're gonna know the username based on who is logged in so the username is going to be all right so username equals session that we're saying user however I want to be able to test this locally so I'm gonna do a little environment swapper room so we're going to do all right so we're gonna set our default all right and we're just developing locally we're gonna say that our default is me and then when you're using when you're using the session dollar sign user and you want that can be identified with the environment variable for our config so let's do get environment variable our config so if the active configuration is RS connect all right this is making sense our config active is RS connect username is session dollar sign user otherwise it's me all right output greeting hello all right and now we also need to figure out what our current name is going to be so we say hello to ourselves and then we now have to define what the current name is going to be so code name under text use your code name let's call it we have to define what that is so let's stick it up here so we've got the pen we've got the pen with our user name and our code name so we're just going to take our code names table filter it username equals username and then we'll just pull so for kicks all right so we say username is this we've got our code names what do we end up with code names where did we where'd we fill out
exposable tuna Oh name okay so it is God makes it even more let's see is that gonna bite us anywhere else there's I see cod I think we should be in good shape okay so let's test this out see if this runs locally
Troubleshooting and publishing
cotton oh my gosh fabulous let's publish this puppy let's go code names generator secret generator oh can't find pull for every D plier to the rescue all right try that again
exposable tuna so from here I guess we could like leave it an exercise to the reader to build out more assets so you round out our secret agent personas
