Transcript#
This transcript was generated automatically and may contain errors.
Welcome back to the Data Science Lab everybody, we're so happy you're here. This is where we share about technical topics, this is where we just get together to nerd out, share screens, and we are all about question asking and transparency. Oh look, I've been posting the links to the waiting room participants and didn't realize it, not to everybody in the chat.
I am so excited to be joined by our featured lab manager today, Daniel Chen. Daniel, would you like to introduce yourself? Hello everyone, I'm Daniel, I am a lecturer at the University of British Columbia and longtime member of the lab crew, hangout crew, so nice to be able to talk here. Founding founding member. And what are we going to be talking, yes, from the beginning, what are we going to be talking about today Dan? Today we are going to walk through a like a basic introduction to Shiny application in R and sort of just show you how I sort of will create a new app and then a little bit of the basics and like how an app is structured and then maybe we'll get it deployed somehow so hopefully it all works out.
It will all work out. I am making everybody yellow as I see you pop up, if you're not already yellow. If you're a different color, that's because you just have multiple roles. You're still, you're still a yellow, I promise. I am so excited about this topic and I was just telling Daniel before we hopped on here how excited I am to talk about basics. Daniel and I are both teachers who teach R, Python, Shiny, for data science, all of this stuff, and I find all the time that I have forgotten bits and pieces of the things that I learned years ago or that even that I teach or think that I know. So we're going to talk about fundamentals today but that does not mean that it's going to be low level or boring. It's going to be fun and if you find yourself with the ability to answer any questions that people have, I would love you as the community to hop in discord and help answer them.
So today you might see people do things like put candle emojis in the chat or you might see things in the chat get flagged with a golf flag. The golf flag means this is a question. I have flagged it as a question or Dan has or someone in the community has helped us out by flagging it as a question so that we don't miss it. If there's ever a question that gets missed, please, please remind us. We're going to try to get to questions. If we can't get to them all today, we will follow up. And then the candles are a vigil for live coding. Daniel, how much live coding are we going to do today? I think it's going to be all of it. Okay, lots of candles are needed. I have some candles off to the side. I know lots of people have a few live candles. There might be some Claude live coding involved, but that's just even more treacherous.
Okay, if you were here last week, you know that we had a whole episode pretty much predicated on the fact that Claude would work for an hour and Claude went down and betrayed us all. So everybody cross your fingers and light your candles. If your name is not yellow in Discord, I'm making it yellow shortly. All right, Dan, let's go ahead and I'll let you share your screen and we can get started. All right.
And everybody, please let Dan know if like the text is too small, if we need to make things bigger, I will try to interrupt him and ask him to make things bigger and we'll get there together. Lots of candles in the chat happening. Thank you, everybody. Thank you.
Raha says Dan is the best live coder I have ever seen and hopefully I didn't just jinx him. No pressure. Oh, Dan, can you share your screen? Are you able to?
He's typing in Discord. This is what we're doing to him. We're distracting him. But hopefully you have permission to. Okay. Yeah. You do. Great. Great. All right, everybody. Can we see? Yes. I think it needs to be just a smidge bigger for text.
Okay. I'm going to try again. Hello. Hopefully. I can hear you. Yeah. And see you. And we are going to try that again. All right. Is that good? Everyone can see? I think I can see. I can see the reference.
Starting a new Shiny project from scratch
We're off to a great start. Okay. So, a couple of things. I'll start creating a Shiny application right from the very beginning as if I was creating something for real. And that actually starts all the way in the world of GitHub. So, we'll go to GitHub.com slash new. That's the easier way to get to this new repository link. And using version control is always a good practice to have.
And the other reason that I like to start my repositories in GitHub, if I know it's going to be under version control through GitHub, it helps with a lot of the plumbing so you don't have to set up repository remotes and things like that. So, we are going to call this 25 VS Lab. So, I usually date my repositories, again, mostly because if I go through this as a tutorial, again, I can literally do the same thing without, you know, with a unique name. So, I usually have a lot of dates in my repository names. It will be public. We don't really need a template, but we can sort of start off with a bunch of stuff if we need just to have a nonempty repository.
Yeah, I learned about the GitHub slash new because I guess I've done enough live coding things where I'm like, okay, here's the quick way to get there, especially when you need to direct students into the, like, just go to this link. So, here's our URL. Here's our new repository. And I have my SSH keys set up. Do I have that set up? I believe I have it set up. I know I got a bunch of emails this morning about some things were expiring. But and this is sort of, like, where some of the magic is, is we are going to bring this folder from GitHub down to our computer. And because we know where in GitHub it exists, when we bring it to our computer, it sets up that connection between our computer and GitHub right away and it saves you a couple of extra steps.
So, and the workflow I'm doing right now is creating a project from scratch. So, like, I haven't done anything on my local computer yet. So, if you sometimes do the workflow of, like, I'm going to start something first and then send it to GitHub, those buttons I clicked, which is oops. Those buttons I clicked. Those buttons I clicked here, you would typically leave them, like, alone. So, you don't end up, like, two different parallel trees and you have to merge that in Git. But we're starting from scratch. So, I'm okay with doing that.
Okay. So, yes, we are totally going back to that. Deposit skills thing. Okay. So, we're going to bring this from a new folder from Git. And the other thing that I typically do as, like, a good thing or a good habit is in my home directory, I have a folder called Git. And you can see, like, I have some, like, subfolders already. But my suggestion to everyone is make a folder called Git in your home directory. And then all of your Git repositories go in that folder. It's a good way to make sure or keep all your Git repositories in one place because sometimes you don't not everything is a Git repository. And this way, yeah, like, all your Git repositories in one place. So, like, you're not, like, oh, here's the OneDrive folder. And there's some Git things there. They also don't like Git folders as well. So, keep everything in a Git folder and create subfolders as necessary.
The other reason why I do this is it's really dangerous or you shouldn't, not necessarily dangerous, but Git gets really weird if you clone a repository inside another repository without setting up, like, Git submodules. And so, this also prevents you from doing something like that where the Git folder is always, like, a clean place for you to clone stuff.
So, we're going to bring this folder down to our local computer. And one of the benefits of cloning it down, you'll see that, like, all of this Git stuff has already been set up and already has it will originally already have this connection to the remote repository. So, that's what this little purple thing is with the cloud. And so, we should be good to start for today.
So, the other reason that I have, like, a Git folder, it's not, like, if you use GitHub for your other work. Me, personally, I also have a folder in my Git folder called private because not all my repositories are public. And so, it doesn't have to be just, like, create, like, a GitHub specific folder. Back in the day, I used to have, like, a Bitbucket account and a GitLab account and they used to have subfolders, but now everything's on GitHub, but then GitHub's been having a lot of outages. So, we're really trying to burn all the candles for today.
Setting up Posit skills for Claude
Okay. Another thing, since this came up in the Discord channel is, yes, Git and GitHub get confused all the time. Git is the version control system and GitHub is where you put the repository the version control system creates. Think of it as, like, the cloud backup storage. Yeah. It's your remote.
Okay. So, we now have our repository and we are going to create a Shiny app. And just to do some of the process a little make some of the process a little bit faster so we can talk through the code is I am going to fire up Claude directly in this terminal and I'll accept the view there. The other thing that I have done in Positron right now is I am looking at this side by side layout. Usually, in data science mode, you're probably used to looking at the four or five pane view for the stacked layout. But since we're mostly going to be looking at the terminal, looking at some code, we're using the side by side layout just so things are as big as they can.
Okay. So, we have Claude loaded up. And then the question that someone saw was this thing about Posit skills. So, Posit, the folks on Posit, a lot of the engineers, have all collaborated or starting to work on a set of skills, which is really markdown instructions to do certain tasks. And so, you can find it at GitHub.com, Posit dev slash skills. And there's a lot of things in here. I typically install it and then check off everything and I'll show you how you can install it on your end. But the more important thing is we really need to make sure that we get the shiny bits involved. Mostly because of Shiny bslib, which is the newer or more modernish way of creating a shiny app in R. We talk a lot about Quarto in the data science lab. They have skills for how to write Quarto files. So, it's a really nice way of directing your LLM to the actual documentation instead of it trying to guess or figure out what to do from its training data.
It's a really nice way of directing your LLM to the actual documentation instead of it trying to guess or figure out what to do from its training data.
So, we can essentially install these skills. And the way this works, somewhere in here, there's an installation section. So, there are these NPM commands, NPX commands that you can copy paste to add. I'm using Claude. So, we're going to add the marketplace for Posit dev skills. So, you literally copy paste that. And then if we follow the instructions here, plugins. Manage Claude plugins. So, you can eventually go to the marketplaces. Make sure uh oh. Discover. Hold on. It's not on discover. Okay. Go to marketplaces. Select Posit. And then you can browse. And then all you can manually select all of these. So, you can see I've already installed a lot of these. But you can use the arrow keys. And I use the what is it? The space bar to select items. And then you'll see at the very bottom it says I to install. So, right now there's a new connect skill. So, I can hit I and it will now install that skill. So, all it's really doing is copying pasting markdown instructions into a dot Claude folder. So, now Claude knows how to do stuff.
And I'm not currently using Posit Assistant. There's a couple of things that we might be
able to show like where the differences between using Claude code versus Posit Assistant shows up. And I think we'll see that almost immediately when Claude starts to write some stuff.
Okay. So, we're going to create a Shiny application. We are currently in TidyTuesday. So, what I'm going to do is have Claude create a TidyTuesday Shiny application for this week's dataset. And I did a quick look before this started. This week's dataset is around country music lyrics. So, that's what we'll be looking at. It was kind of funny because last week's was about the IELTS English exam. And it's pretty funny. My immigration process to Canada, I actually had to take CELPIP, which is another English exam. So, it would have been kind of fun to look at English exams. But this week we're on country music. Since the other thing that we've done, we can set a model. I don't think we need Fable. We'll just leave it at Opus right now because I kind of want to also save my tokens. So, we can set the model that way. We can set the effort to max. Sure. Maybe that's the way of balancing me not wanting to use Fable for this.
And all that's going to do is one of the tradeoffs that you're doing is time to first token or forward to do stuff. Okay. Let's actually go ahead and create this application and then I'll talk about other stuff as it's kind of thinking. So, we're going to say create a Shiny app with this week's tidy Tuesday data. We'll say keep it simple since this is a live demo. Create it in a Shiny. The reason why I want to really specifically say keep it simple is because it actually will if you don't, like, tell it to keep it simple. What I've done right before starting is it made like a full blown, like, with theming and colors and all of this other stuff.
Which is really nice, but it's a little bit too complicated of an example for just showing you how things work. So, this is sort of cooking in the background. You'll notice that, like, it's finding today's date and it's getting the contents. And if I very quickly look, like, yes, it is on country music lyrics. I'm also in auto mode. So, it's just going to just do its thing. But typically, I've been starting to put this in plan mode and reviewing plans. But then you end up prompting it. No, Libby, I cannot hear you.
Don't think can anybody hear me? Thumbs up for me if you can hear Libby talking. Okay. Hold on. Hold on. Hold on. Okay. Raha says y'all can hear me. Anika says okay. I want to make sure Dan can hear me so that when I interrupt him to ask y'all's questions that he actually gets them.
Okay. So, this is a me issue. I think it's Dan's computer. Yeah. Oh, wait. I can hear you now. You can hear me? Yes. Now you're the Verizon guy. Okay. I wanted to make sure that you could hear me so that I could ask you the questions that I see in the chat. Because I noticed a few times I was like, wait, I don't think Dan can hear what I'm saying. Okay. We fixed it, y'all. We made it. I wanted to say for anybody who had the question of how Dan got to the marketplace, because Amin had asked in the chat, you can literally type slash marketplace or slash plugin and you'll get there in Cloud. So, there's slash commands in Cloud that will get you all kinds of places. So, if Dan types a slash, you'll see them kind of pop up his little options. So, you just type slash marketplace. I believe.
Yes. Yeah. Yeah. I'm just out of yeah. There we go. It's also the same as slash plugin, but yeah, you'll see slash marketplace. And in the instructions here, you'll see it like documented that way as well. Wonderful. Oh, plugin. I think I pluralized that. I'll go fix that in my oh, no, I got it right. Plugin. Yeah. So, this is adding it. This is adding it. And then I by habit, I go through the marketplace or through plugin. It's the same thing. And I find things through the menu system.
Reviewing the generated app
Great. Okay. So, that's great. You'll notice that, yes, it is it has mentioned that today this is the correct date. We are using country music lyrics. And you'll see right here, it said skill shiny, shiny bslib. So, it is actually understanding that we are creating a Shiny app and we are creating a Shiny for our app and Shiny for R these days is using bslib instead of the original functions that come with Shiny to create the UI. And that's mostly because of the updated bootstrap library or CSS framework that's on top of Shiny to make things, quote, unquote, look a little bit better. And you can see that being loaded right away.
The other thing around skills with agents in general is I personally don't have that many skills loaded. A lot of some people just have they try to add everything and they get a little bit overboard. All of those skills and the description metadata get loaded in the context. Which means that, like, I'm on Opus right now, which has a million token context, which is totally fine. But if you're on other smaller models or if you're running on something local, those skills and everything, the agent needs to know that it exists. And knowing it exists means it needs to have some text written and that means it's in the context window. So, that's a little balance between, like, adding everything that you think is cool versus, like, just add what you need. Okay. So, we're running country music data and it says the data is clean and you can see that it's reading in this data set and it downloaded it and it created this app.r file. So, before we just continue, I'm just going to run it and see if this thing works.
And then we'll talk a little bit about what's happening code wise. Okay. Great. And Dan clicked the little play button. Positron has very minimalistic icons. And so, if you want to know what they do, you have to kind of, like, hover over them for a second. But there's that little play button at the very top. That's what he clicked to go ahead and run the app. And Dan, I wanted to ask, because we are talking about, like, fundamentals of building a Shiny app in 2026, I feel like it's important to just point out that, like, you haven't done a ton of stuff granularly by hand. You are relying on an LLM and that is sort of the direction that a lot of people are going towards. Do you still think that there's value in learning the nitty gritty, step by step, building it yourself stuff? And are we going to talk about that?
I think, well, in general, these days, I think it's especially writing a dashboard, you can confirm it by the dashboard actually working and loading, which, you know, it is not loading right now. For reasons unknown.
Sometimes I pop it out in the browser and then it works, too. And I'm like, hmm. Yeah. It might also be the nope. All right. Hold on. We can do this. We can figure this out. Why?
Annika says, as a beginner, I find it amazing that you can just tell Cloud to create an app with no input about what to actually do with the data.
Yeah. So, in that sense, it's really nice that you can get started very quickly. I would say, like, I have one-off projects where it is completely vibe coded. It is in JavaScript. I actually have no idea what's going on in there. And don't ask me to, like, tell you what's going on. Which is actually very scary. But you can actually create things, which is really nice. And if that's your goal, I just want to create something that solves something really specific for my current need, go for it. Do you need to understand everything that's going in there? Probably not. If you are trying to create something that is, you know, for work and, like, the and the answer and the details actually matter, this is sort of what this is sort of the context I try to do things in where all right, we're going to we're going to, like, try something else. The way I do it is really similar to how I prompted this app, which is, keep it simple really for now. Give me something that I can actually review, like, almost line by line and then review it that way. So, you're not asking it to create this full-blown analysis. You're actually creating little pieces, something that you can understand, and then you can build on it. So, that's sort of what I've some of the workflow that I've gotten used to doing.
keep it simple really for now. Give me something that I can actually review, like, almost line by line and then review it that way. So, you're not asking it to create this full-blown analysis. You're actually creating little pieces, something that you can understand, and then you can build on it.
Okay. So, the little button is not working for some reason. So, we are going to say what is it? Run app? Run app? Shiny run app? Shiny run app.
Okay. We're going to run that. Okay. R script dash E. I'm looking at the bottom of your Positron, and it says problems 11. I'm wondering if maybe that is part of why we have an app that's not running. It's my spell checker. We'll just ignore that.
What is what is it's already in use. Okay. So, we are the other thing that the this thing is doing is it loaded up on a random port. Usually when I'm working, I try to oh, there it is. Okay. We'll just make a new one. I try to keep the port the same, and that's just so when I reload it, I can refresh the same web page and it just reloads. I'm just getting rid of that right now. Just because I have no idea why it wasn't working. Sometimes when the screen is zoomed in too much, it just doesn't know how to render stuff. I'm hoping that's the reason. But here's the application. It seems like it's doing its job. Here's some search terms.
We have some cards at the top. So, these are you know, you can think of this as like KPI metrics. There's like a little figure here. This is using ggplot, I believe, because it's static. And then you have a viewable table down here. And off the bat, you can see throughout the years, the word girl shows up in country music a lot for reasons unknown. But it is a very commonly used word in country music. I don't know if it's it should be normalized to other music genres. But that is the really basic dashboard that we have. And it's got a title, it's got a little sidebar, and all those components. And then let's go into the application and see where everything is coming from. We need shiny. So, that's good. bslib, this is where we get the newer UI infrastructure to make things a little bit prettier. So, like, these card elements here, like, you see this little somewhat small drop shadow around these boxes. And the title here instead of a ggplot title, that is all part of bslib.
There's going to be some data wrangling. So, we have the plier, ggplot2 for figures, and then string bar. Okay, cool. So, the first thing, one of the things that Claude does for better or for worse, I think it's a good thing, is Claude actually writes a lot of code that does, like, these conditional checks. So, you can see here, it's like, hey, here's your CSV. If it exists, then go and actually load it. And then sometimes it will throw in an error, like, else, like, just error out, right? So, Claude does end up writing a lot of safeguards for itself. Part of that is sometimes the LLM or the agent, really the agent, not the LLM. So, the agent is the thing that is just, like, able to run all the commands, and the LLM is the thing that, like, can generate it, generate the words. The agent will sometimes run your application, and if it sees an error, that's why it will know roughly, like, where that problem is and tries to solve it. And that's why it ends up writing a lot of, like, test cases, which is actually kind of good.
It's, like, a good habit as you start to read. Because this is stuff I used to never write. Okay. So, now that we have this. Even today, I probably don't. But also, it's, like, it's also fair to say, if you're a beginner, and this is your first Shiny app, and also you're new to coding and programming in general, you probably don't write those or think to write them or maybe even know what that is doing. So, like, don't be afraid to highlight that, paste it into Cloud, and be, like, what are you doing? What is this? Like, ask Cloud what it did so that you can learn and understand.
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com
https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com https://data-science.blogspot.com