Transcript#
This transcript was generated automatically and may contain errors.
So welcome back to the Data Science Lab. If you've never been here before, we are an open space where we talk about technical topics. We often have just one topic where we are learning something with somebody. And the whole point of the Data Science Lab is that we get to stop and ask questions. But every once in a while, and I'm hoping more often, we do a project showcase where we can have people from the community come and share something that they did and talk about something that they're proud of.
I'm excited to introduce our featured lab managers for today. You already met Isabella, Isabella Velรกsquez, myself, and Dylan Poulsen. And Dylan's going to go first. So Dylan, would you like to introduce yourself real quick? And then I will start a 15 minute timer for you. Yeah, absolutely. So my name is Dylan Poulsen. I'm an Associate Professor of Data Science. I was formerly a Mathematics Professor with Applied Mathematics and Engineering Training. And I've recently taken on leading our Data Science major here at Washington College, which is a small liberal arts college on the eastern shore of Maryland.
I'm really most famous for something that I'm most proud of, but also most embarrassed by, which is what I'm going to show you today. So this is a story that I want to tell. And I think it has good data science lessons for this community. Because you'll see, I was ultimately wrong about things. And I love, I love the fact that I can share this.
So yeah, so I'm going to tell, tell a story of mathematical levity, mathematical joy, and community. Awesome. Okay, I'm starting your timer. I will check in with you as needed on little time updates. Don't mind me if I interrupt. Take it away, Dylan.
The onion constant
Yeah. Okay. So this is the story of the onion constant, which is a new mathematical constant that I came up with. And this number that's represented by this step was published in the New York Times and the pudding, and a few other news outlets around the world. It was for one day very randomly on the top page of Hacker News. And I think it can show us the joy of just doing things for fun.
So the problem began from this Instagram post by Kenji Lopez-Alt, who is a really famous chef and content creator. And he posed the problem of how do you make, how do you cut your onions so that the pieces are the most uniform in size. So he demonstrates in this post, we had the vertical cuts, which you can see you get like large pieces over here and small pieces in here. You can do a radial cut method, which is recommended by a lot of chefs, actually, to aim towards the center of the onion. Or you could aim below the center. So to a point somewhere beneath the center of the onion.
And so this is, to me, this was a very suggestive problem. And I actually found out about this from a friend. And then after hearing about it, my friend had mentioned that the depth that Kenji had come up with was 60% down, which sort of, which is close to the golden ratio, because the ratio 1 to 1.6 is the golden ratio. And so it made me think like maybe the golden ratio is involved in this. How can I think about this? So every single night while cutting onions, because I have onions every night, I would just think about this problem and enjoy the retreat to thinking about something just for fun.
And then one thing I realized is if you look at this middle picture, I teach a lot of mathematics. There's a lot of joy in doing that. But one thing is when you teach a subject, you see manifestations of it in the world. And when I looked at this picture, I saw the polar coordinate system from multivariate calculus. So the idea being you can measure, determine a point by how far it is from the center and the angle that's made from the center. And what I realized is that the contours of equal radius are the onion layers, and the lines of equal angle are the knife cuts that you would make.
So I envisioned a infinitely many layered onion where you were making infinitely many cuts, and realized that pieces would have a distribution to them. So there's a probability distribution in these pieces. Pieces closest to the center are smaller than pieces towards the end relative to each other, and that they're actually distributed according to a uniform distribution. So for some of you who like the probability theory, that might be piquing your interest.
And it's actually the Jacobian determinant that gives that probability density function, because the Jacobian determinant for the radial or the polar coordinate system is r, and r is also the probability density function for the uniform distribution. I don't want to get too technical here, because it's mostly about sharing the story.
But this is the paper I wrote about it. This is the image I had in mind.
But then I realized that doesn't solve the problem for Kenji, but it gave me the lateral move that I needed. I realized I could think about measuring the distance from the center of the onion just in the usual way, and then the contours are still the onion, the onion layers. But I could measure the angle from a depth h below the onion. And still the Jacobian determinant would tell me about the way the pieces were distributed.
So then it just became a calculus problem. For those of you who know your calculus, I took the derivative of h, or of the function with respect to h, set it equal to zero. Sort of classic calculus, right? But the function that I was dealing with was pretty terrible. If you watch, I can show that. But yikes, right?
Yeah. You officially lost, Libby.
Sharing the work and collaborating
So this is fun. And I wrote a blog post about this, which I think is in line with the values I see in this community of sharing your stuff out loud, learning out loud. And word got back to Kenji. How'd that happen?
So one thing I did, just like maybe selfless self-promotion here, I left a comment on his YouTube video where he had first talked about this problem. And I said, oh, I'm a mathematician who got really obsessed with this. Here's my solution. And he actually responded to that. Amazing. If you have a link to that paper, it went over my head, but other people would like to see it. So Rahat has it in the Discord.
It's in Mathematics Magazine. And I will put the PDF in the Discord. Perfect. All right. No rush now. As a time check, you've got eight minutes.
Perfect. Yeah. So Kenji asked if he could maybe use this paper in another video. And I said, absolutely. That would be wonderful. And then a year went by and nothing had really happened. And then I got a message from my friend. It's like, your name's in the New York Times today.
Kenji also has a column in the New York Times and so had written about this problem. And so he talked about his tinkering with it, how he made a computer program to study it, and then how I had taken that and run with it and made a big mathematical model for this.
And that was sort of, that felt like the bow on it. It's like, oh, you solve a problem and it ends up in the New York Times. But that isn't really the lesson I want to impart today.
The lesson is that when you share your work, other people read it and run with it and get in contact with you and start collaborating. I had a person named Matt Sandler, who's a data scientist, reach out to me with his code. He had, so I have that open here in Positron.
The lesson is that when you share your work, other people read it and run with it and get in contact with you and start collaborating.
And so he had actually done some stuff in Python and was shapely. Oh my gosh, that's beautiful. Yeah, and trying to calculate the area of the pieces and the standard deviation of the pieces.
And this is, this was really cool. He was getting results that didn't agree with me. One reason why is because he's actually using finite cuts and finitely many layers, which is not what I did, right? I made this abstraction to infinitely many layers and infinitely many cuts. That's very, very mathematical. Here it's actually like getting into the raw data of the cuts. I was actually able to take his code and instead of doing 10 cuts and 10 layers, I did 300 cuts and 300 layers. And I saw that my results agreed with his in this limiting process, which was pretty cool to verify.
The coefficient of variation
But I think the coolest thing that was in here is while he calculated the standard deviation, in some places he actually used what's called the coefficient of variation to measure how the onion slices varied in size. And I was looking at this and then I didn't know if it made a difference to the results, but I ran through and it actually does make a difference. Moreover, this is the better metric to use. And I want to talk about why, because I think this will resonate with the data science audience here. There might be people in the chat who already see why. Well, not me, but how did it feel to figure this out post that New York Times article?
It was a little scary because you put your stuff out there and you're like, oh, and now someone's saying I'm wrong and now someone's doing... But it was never malicious. And what I had to get past and especially with all the attention is just when you start debating ideas, that isn't a debate against you individually.
You were brave enough to put it out there, which meant you got to have this conversation about mathematics and the coefficient of variation in the first place. And it was so much fun. And everyone, the conversations were just wonderful and I feel like I made an internet friend through these interactions.
But the coefficient of variation is a measure you can use that allows you to compare how much a quantity varies, even when it has a different mean. And I want to show you the importance of this by thinking about my favorite example, which is if I had a data set that was weights of elephants, and I also had a data set that was weights of mice, the standard deviation of the mice weight data would be less than the standard deviation of the elephant weight data. But if you calculate the coefficient of variation, they become comparable. It's the ratio of the standard deviation to the mean. And one thing that's in this paper and in these ideas is that the average onion slice area also varies with age. And so you can't actually compare them all as you vary the depth that you cut towards. So it's like mice and elephants, and we need them to be able to be compared.
So to me then, there's actually a different onion constant. So the one that's in the New York Times is 0.557. It's this number right here. Whoa. Do you think you have enough numbers for accuracy?
When it comes to math, there's never enough, right?
Isabella says, is it transcendental? It is. But this is the onion constant when you use the coefficient of variation. It's 0.757. Oh, that's quite different. It is quite different. And I was amazed by this. So I even wrote in my paper here, right, I don't think of the two dimension, the variance onion constant as the wrong onion constant because the math is correct. But the coefficient of variation onion constant is the solution to the better question.
But the coefficient of variation onion constant is the solution to the better question.
I love that. I love that. This was so fun. And we do actually have a couple of questions in the chat. We had one from Zach. Oh, Zach, where's your question? It is, do you think this problem could be approached using complex numbers?
Hmm. Possibly. I have not explored that at all, but my encouragement is try it out. Have it a go. Do it. Report back. Awesome. Also, Rob had asked, what's that character for the onion constant? Oh, yeah. It's a Hebrew character, and I hope I don't butcher it, Samech. Okay. And chosen because it looked to me to be most like an onion.
It does look like a little onion. It's very cute. We also had one from Brian that said, what if you minimize the coefficient of variation in the surface area of the pieces?
Can you repeat it? Sorry. I was closing windows. It says, what if you minimize the coefficient of variation in the surface area of the pieces?
I haven't done it for surface area because that was actually the two dimensional onion problem. So you're thinking of the onion as being a two dimensional object. I have done the minimum coefficient of variation for the three dimensional volume. Which I like. I like. That's just different ways to think about it. Emil says, we need to get this on the onion, which seems like an appropriate outlet. Does anybody know anybody who works at the onion? Please help us get on it. Please.
Okay. Well, Dylan, that was amazing. That was so much fun. And I want everybody to also look at the pudding article just because the onion font is so glorious. I don't know who made that onion font, but some designer at the pudding had a lot of fun with it. Isabella just put it in the zoom chat. And I think that she'll put it in the discord as well. You can probably see it. Yeah. In the preview that shows up from the embedded image. It's just so cool. And all the way through that pudding article, you can see this onion font used in different ways.
I'm obsessed with it. The moment Dylan shared this, I was obsessed with the font. I've had alums from the college reach out to me being like, I saw the pudding onion font on Instagram. It's so good. It's so good. Whoever made that amazing. And thank you to you for bravely solving this problem in public, even though you feel like it wasn't the optimal solution to the optimal question. I think it's a great illustration of putting yourself out there, doing work that you care about, even if you think nobody else cares about it and finding out that other people actually do. And it's really fun. And also everybody go check out Kenji Lopez all because he's just absolutely wonderful. I love watching him on YouTube.
Libby's Ellsworth Kelly app
Okay. Well now it's my turn. I'm so nervous. I'm going to share my screen and hopefully I'll share the right one. And I'm going to start my own timer. By the way, I am Libby Heron. I run community here at posit. I'm also a data scientist by trade, even though I now do this stuff now. And I'm going to tell a story of how I built an app that nobody asked for, uh, and took like a year and a half to do it.
So this is the story of the Ellsworth app and this is how it started. This is my inspiration. This is not my picture. This is a picture. Um, that I think this is one that's close to what Stacy Taylor, who is the crooked him, this is her, uh, her blog posted on Instagram. She posted, I'm making a quilt that's, you know, inspired by Ellsworth Kelly. And isn't it pretty. Right. And my brain was like, Oh, I love this so much. I love color. I love spectrum color. I love everything about this. Right. So this is her blog post about it, that she made a little bit later. And you can see that she has little squares of color, a fabric, and you can tell that there's some randomness going on here. I love randomness and probability. I'm a stats kid. This is exciting for me. Right. So I messaged Stacy immediately on Instagram and I say, Oh my gosh, I'm so excited about this. Um, my brain wants to code this. My brain wants to code an app. And she's like, well, go for it. I just did some stuff in Excel and I'd love to see it. Right.
Um, so I went from this inspiration to let me Google Ellsworth Kelly, Ellsworth Kelly did the spectrum colors arranged by chance series in the 1950s. This is the piece that Stacy's quilt is inspired by. It's, um, the number three of the series and these three pieces specifically, this is seven, four, and three were very, very, very inspirational to me. My brain just picked them apart. I was like, Oh my gosh, how did these, how are these conceived? How are they made? What are they made of all of the things? Right. And if you see all of these say collage on paper, it's quite tiny on my screen. So it's very hard to see. And they're all 39 by 39 inches.
Um, so I, instead of doing a bunch of research on Ellsworth Kelly, first, I just dove into thinking about probability and how this might have worked. Um, and you can see on my blog, this is part one of my blog where I took a picture of my favorite, which is that number three over here on the side. And I dissected it by hand, uh, using procreate on my iPad. I was like, I'm going to count all the things. And you can see me counting like the circuits, right? Like starting at the center, we have a circuit of four and then we have a circuit of more than four. And then we have a circuit of right. And they keep going. Here's me trying to figure all of that out. 40 plus 40 plus 38 plus 38. How much is all of this? And here's me trying to do math and me saying, no, I'm wrong. Right? Like I did a bunch of incorrect math. I'm not a mathematician. Uh, Dylan, close your eyes for most of this. Uh, but I knew that it was exciting and I wanted to work on it.
That this was the point where I stopped and did a little bit more research from Ellsworth Kelly, uh, like interviews with him and stuff. And I've wished that Kelly had put this out a little bit earlier, but much later she put out how she did it, which is in Excel, where she created some different matrices of probability and randomness. Um, but she had not put this out and I had not seen it when I started. And I was actually really glad for that because it meant I got to struggle through it my own way without any inspiration for how to solve this problem. Um, and my problem was I knew that there was an increase of probability from the outside in, right? So the inside starts with like a hundred percent probability that we're going to have color. And then as we go further out, there's less and less probability of color appearing against this background. And when I did my research for how Kelly made this, it was very much like Stacy's little bits of color, right?
Um, he had his limitations were what colors existed in this paper that he was buying in France, right? This like colored paper. Um, and so he had this like stack of different papers. He had them all cut up into little squares and he basically had them in a hat and he could draw them out by random. But the important part was that for his different pieces that he made, he gave himself different constraints for where and how often the colors were placed and also which colors could be next to each other. Because if you look at these pieces, um, you'll see that there are not a ton of repeats. There aren't more than like two colors next to each other. See how there's like two here and there's, there's a couple that are closer together, um, and other places, but there's not a lot of right next door repetition between color. And I knew that that would be a mathematical problem to solve or a comparison problem to solve.
Um, so I went through and I did all of this by hand and I did a ton of pseudo coding by hand and really I didn't code anything at all. I just started writing down my code and my ideas. I wanted to share all of this. I just wanted to like have the goal of writing it down and keeping track of it and just showing what my process looks like. Cause I'd never shared it with anybody before. So you can see all of it and it's all very, very messy. So the main things I want to share are how I got inspired, which is through somebody posting about their quilt. The idea that I couldn't shake was just that I wanted to make this app. Um, and then the mess, sharing the mess, right? That was the whole point. So I can't show you this entire seven part blog series. That would be banana pants. There's no way you would be very, very bored, but I do want to show you just some of the mistakes that I made and that I, um, that I recorded.
Mistakes and the messy process
So one of the first things is that I miscounted twice, like here when I'm counting all of this stuff, I counted two or three or four times and I kept coming up with different numbers and I was really frustrated. Um, and then I did told you I stopped and did that research. Like how did Ellsworth Kelly do this? And in an interview with him, he mentions, Oh yeah, I knew that with every increasing circuit of grids, the number of squares increased by eight, super easy, just plus eight for each one. I wish I had read that a lot sooner because this was like a day of me struggling and feeling very, very dumb. Um, so yeah, I say it again. Wow. Wish I'd read that interview with Kelly saying this much earlier.
So I was like, I'm going to need to create a matrix of probabilities. I'm going to do all this stuff. I did a proof of concept and my initial code was focusing on a matrix when really I could have just made a vector. I figured that out eventually, but I had to get through the struggle to do it. Um, and I also wrote this like really convoluted piece of code where I absolutely just like kind of did everything wrong for a long time. Here's my proof of concept. I was so excited. I was just taking screenshots on my phone because I couldn't even, I was so excited that I couldn't even like, uh, properly screenshot. I said I was drunk with power at this point. I am just like made a thing that sort of worked and I was really, really excited, but I knew that at that point I needed to, to go further. So I wrote this like very convoluted thing where I'm like, you know, here's all the math that's going to work things out. And I struggled for a really long time. There was like a bunch of code that looked like this. Um, this says, this goes on for some time. I'm going to spare you. Eventually I got to a solution I liked, but you'll see that I say still ignoring the fact that I could just subtract, there was an easier solution to my problem the entire time to all the math I was doing. I was writing a bunch of math that just avoided subtraction. I don't know why. Subtraction was the easy thing to do.
Um, here's my pitch for the book Subtract actually by Luddy Klotz. Definitely read that. I'm going to put it in the chat. Oh, that's a super annoying Amazon link, but, um, that is like a book I wish I had read at this point. And I had not yet. I don't think, um, the other mistake that I made was I kind of theme voided myself when I was trying to make the, the ggplot of, of these probabilities to make sure that I had them right. Right. Like, do I have my probabilities right? Are they clustered in the center? Are they further dispersed on the outside? See how I have nothing on the outside because in my code, I am getting rid of it. I'm like, Hey, get rid of this. Like, you know, access access text. Right. Why did I do that? I don't know. I just did it.
And I continue to do it. And the reason why I couldn't figure this out as I like continue and continue to fail and I get all upset and I'm like, why isn't this working? And I'm testing and I'm testing. Um, look at me. I'm like, this is definitely not correct, but why I've done something wrong, but why, what is it? I'm just trying so hard. Uh, there's a note from future me that says, this is hard to watch. Think about how ggplot makes plots. And I had to kind of stop and, and come back to it later. And this is my, my second part here saying, Hey, uh, Libby's about to feel really silly. Just watch. Because what I do is I go back to basics. I go back to just a regular ggplot. Here it is. Nothing fancy, which means I'm leaving these on. And then I realized that the index, the origin is zero zero in the bottom left. And this is the point that I had just completely forgotten about, even though I had taught ggplot for years, right? And like, it was very embarrassing. Um, so here I am saying, Hey, oh my gosh, the axes start from zero in the bottom left and they go up from there. And this is my problem. And this is all I needed to know to fix my problem and hooray, get something that is corrected. And, uh, you know, by the, by the time I, I figure it out, right. I'm so happy. I just figured it out.
Yeah. Dylan has a note that he loves the recorded thoughts of the moment. So often we produce a clean product without seeing all that goes into it. And I remember Libby, when you and I were doing our first collaboration together and I noticed, cause I definitely do that. I only end up with the final code, but you are so good at writing comments as you are changing, editing. There's a comment for every line here. Y'all this is how I work. No regrets.
Um, there was another question from Dylan. Do you think these handwritten notes are valuable in today's age of AI? I mean, I hope they are. And part of my hope for this was that I could just show people that everybody's brain works differently. So if your brain works differently than mine, you can see an example of somebody whose brain works differently and maybe be inspired to think about your own process. Do you write stuff down? Why not? Why? Um, but also there's so much fun in looking back and being like, look how great I was. Look at me. I'm like, no from future Libby. Gosh, I love her. Look at the wonder and enthusiasm. This is the best, right? Like I got to watch myself as I'm rereading this and re I'm putting it on the internet. Um, it was just wonderful.
And the only other mistake that I thought was really funny was that I wrote, I wrote this code where I knew in my brain, I need to grab a random number. Uh, and it needs to, I need to compare that random number to every single cell in whatever this matrix, matrix matrix says that I create, but I just grabbed one for the entire data frame. Like I didn't put it in a loop. It grabbed one for everything. And so my resulting thing was just a binary yes or no, completely wrong thing. And it was so fun to figure out where I was like laughing so hard at myself. Nobody else was in the room with me, but it was hilarious. Um, but anyway, that is most of what I want to share is that recording your problems as they're happening are so great. And then the only other thing that I thought was so fun, this was all me like by myself, right at the end I got on discord, I got into the shiny channel and I just posted, like, you know, I like my app and here it is. Um, and I'll show you the actual website in a minute, here's the gist of the app. And I'm like, you know, I can make it whatever size I want. I can change the background black and white, and then I can create my art piece and there it is. And also there's a little PDF that we can print out here. So if you want to create a quilt, like my original inspiration, you can, and you have a swatch, right?
Um, but the problem was when this is small and you create art piece, you don't know that anything has happened. You don't know that anything has happened. Like, you have to scroll down. And I had some little instructions here that were like, scroll down, scroll down. But nobody could use my app. It was completely useless, because you can't tell what's going on. So I posted it to the Shiny channel. And Adam Higgard, who also works at Posit, but is an engineer, not a data scientist, and has some web development experience, who knows, like, you know, HTML much, much better than I do, saw that. And he was like, oh, you can just use this little line of code. And I'm like, what? What does that mean, Adam? I don't understand. Because for him, it made perfect sense. For me, it was complete nonsense. And he was like, oh, well, it just, like, you know, modifies scrolling behavior, like, automatically. I'm like, okay, I'm going to ask ChatGPT for help at this point. I hadn't asked ChatGPT for much help at all. This was years ago. And we weren't really using LLMs for anything. But I asked it how to insert it. I'm like, I know I can use a tag. And I know I can use HTML. Help me insert this. So this is this little piece of code, which I will uncomment here. And I'll run my Shiny app again. And now, when I create my art piece, it automatically scrolls right to my art piece, which is exactly what I wanted. And I never would have figured this out, because I didn't know HTML could do this. So the moral of that story is, hey, go talk to people who have different backgrounds than you do. Be really vulnerable. Let them know that you don't know what they're talking about. And ask them to explain things like you're five, right? Like, those are the ways that you can move yourself forward. You have to be vulnerable enough to do that, to ask for the help in the first place, just admit you don't know what you're doing, all of that. Because now I'm incredibly happy with this. I love it so much.
hey, go talk to people who have different backgrounds than you do. Be really vulnerable. Let them know that you don't know what they're talking about. And ask them to explain things like you're five, right? Like, those are the ways that you can move yourself forward.
And, you know, it's not useful to anybody. But that doesn't matter to me. I love it. And here is my app in all of its glory, with all of the scrolling. And share it, someone just asked. Here, I'll stick it. I'll stick this in the chat for y'all.
But that's it. That's me. That's my story. Dillon convinced me to share about this, because I was convinced absolutely nobody would want to hear about it. And I really appreciated that he did. Thanks, Dillon. And Colin, too. Colin, I know that you were here earlier. I hope you're still here. Colin encouraged me about it as well. Okay.
It is time to move on to Isabella and Les. We have some other questions. I see Makarand, you were asking, is it published? Yes. So the link I just put in the chat. And let's see. Was there anything else in here that has a gulf flag for a question? I don't think so. I think there was a very early on question. I don't know. I can't find it. About the most about the most optimal solution that you found? Oh, okay. So I did do a small code review with my friend Santiago, who is sometimes here. He's usually not on Discord. But I sent it to him and was like, do you think I could make this any faster? And he was like, you know, honestly, it's probably fine. He did review it and he was very nice about it. But I think the only thing that I think that I could have that could have, you know, maybe made it more optimal was perhaps doing it the way that Stacey did it in hers. So what she did was she created just two matrices, one of her probabilities from the outside in or the inside out, and then one of random probability for I think for whether or not it was filled in. And then she just layered those on top of each other. And what she started with was just a binary sort of black and white. And then she used her like hat of colors and her determination, just like Ellsworth would have done to decide where her things went. But I needed to replicate that human thinking process of taking something out of the hat with math and numbers and code and stuff. My question and what I've talked to other people about before is just like, this is a good example, I think of a type of problem that maybe needs a human brain and maybe wouldn't have been solved very well by just giving it to Claude, right? Like Claude would have been like, why would you want to do this? I don't understand.
But there is a lot in there in that seven part blog series of me trying to figure out the optimal solution for like, getting the sort of probability curve correct for when I made things bigger and smaller. So like, how big can I make it? I can, it only makes sense to go up down to 13. And how big can I make it? It really only made sense to go up to like 60. But you can go as big as you want mathematically and what looked best, where was it, you know, originally it was like 40. So those were some of the sort of constraints I had to work with. And then once we switch it to black, I'm going to remove black as a color option. So there's all kinds of things I had to think about. The hardest part was actually getting it to not repeat colors. There's probably like two whole blog posts just on that. But that's it for me. Let's move on to Isabella. Isabella, I cannot wait to hear about creating a theme for Positron because I think that's what you're going to talk about. I thought you might talk about PyCon, but we have a change of theming here.
Creating a Positron theme
Thank you. And thanks everyone so much for joining. So I am going to talk about the journey that my older brother and I took to create a Positron theme called Tomorrow Night Bright Art Classic. And my older brother is amazing, a true inspiration. He's really the only reason I joined the art community. So if you're watching this Vita, thank you very much. Changed my life more ways than one. And so this is what it looks like. And so the inspiration is in RStudio. Tomorrow Night Bright is generally the theme that I use for my day-to-day coding. It looks like this. It has this really nice kind of like dark background and really bright colors. And for me, it's like really easy to see and everything like that. And we ported it over to Positron.
If you've never installed a theme in Positron, what you can do is in your sidebar, there's an extensions tab. Click on that, and there should be a way to search extensions that are available. And you can search Tomorrow Night Bright. And I already have it installed, but there would be an install button here. I also have the link if you would like. And I would also really love to shout out Shelby Level, who also created Tomorrow Night Bright 80s, our classic, in case this is your favorite RStudio themes. It was amazing. Thank you, Shelby. And then if you have multiple themes installed within Positron, if you open the command palette, which is Command Shift P, and click Preference Color Theme, you can rotate through the different themes and pick the one that you are interested in showcasing in that moment. I'll just leave it for Tomorrow Night Bright for now.
And so in terms of RStudio, in case you've never seen how to switch themes in RStudio, if you go to Tools, and then Global Options, and then Appearance, you can install themes from here. And so there is a package called RSThemes by Garrick Aden-Buie, and it has a ton of other themes that you can install in RStudio. And one of the other ones that I really like is this Ally Dark from RSThemes, and it's meant to be optimized for color accessibility in terms of its contrast and the colors that it chooses. If I hit Apply, you can see what it looks like here. It's a little bit more muted, but generally when I give demos or things like that, this is the one that I like to go with. So I wanted to show very quickly how you could get started in creating your own theme if you're interested.
So here is the link for RSThemes. And then if you go into the Inst folder, and open that up, and if I find it, here we go. You'll notice that the theme is in a Sass file, .scss, and this is what it looks like. So the file type for editing themes in RStudio has a .rstheme extension. For VS Code, Impositron is forked off of VS Code, it's a .tmtheme extension. And versus like a Sass file or CSS file, .tmtheme is an XML file, so very, very different structure. And so what I did was essentially, I opened up a new project and gave it to Claude. And I will say, AI has its use cases, and I think this is a great one. Basically, I gave it the .css file that you see here, and I was like, hey, can you make this into a .tmtheme file? And if you've never seen an XML file, this is the way that it looks like. And if you'll notice, it's very different from CSS. And to do that by hand probably would have taken a very long time, but AI did that in a few seconds.
And so my brother and I wrote a blog post, I don't know if I shared it or not. If not, I shared it again. And as I was reviewing the steps that we took to show you today, I have to admit, I basically followed the blog post. So I hope it is helpful for you if you're interested in doing your own. But essentially, the beginning part is installing all the things that you need to install. So for example, Git, if you don't have Git installed, Node.js, NeoVim, and then finally something called Yeoman. I believe that's how it's pronounced. And that's what's actually going to help you create the extension. So just know, I already have all these things installed. If you're starting from scratch, you will have to install these things yourself. But then in a terminal, which I hope you can see I made it as big as I could, if you type in, let me open up a new one.
I'm going to enter my RPy folder, and then I'm going to say yo code. And this opens up what we need in order to start off our extension. And so you'll see, there are many different kinds of extension. Theme is just one of them. But I'm going to go down to new color theme. And the reason that I had converted that SAS file into a .tm theme file is that there is this option for importing an existing theme and then inline it with the Visual Studio Code color theme file. So you can definitely start this off completely from scratch if you would like. But since I'm already referencing something that exists, and also just to do things a little bit quicker, that is like an option for you as well. And so I have it in this gist. Not sure which one is correct. I'm sure it's gist. And then if I say yes, import this existing theme and inline, if I give it the raw file from the gist, just from, you know, the little snippet of code. Right. And then from here, I can do things like name the extension,
like Ally Dark, I don't know, RS Classic. Could keep the identifier the same. I could do an Ally Dark theme for Positron. What's the name of your theme shown to start? This is fine. And then you can select a base theme if you want. I'm just going to do dark, initiate a git repository. I'm going to say yes. It's going to prompt you if you want to open the new folder with Visual Studio Code, but I'm going to show how to do it in Positron. So I'm going to say skip.
And so if I head back over to Positron and open up RPy and then Ally Dark, RS Classic.
And so here we go. So basically what that did is create all the files that we need in order to make an extension. And so there's lots of things in here. Just a really quick, like, rundown. There's a quick start. There is package.json with, like, the metadata. And then the most important one is under themes, the Ally Dark color theme JSON file. And this is where we're actually going to change our file, change our theme in order for it to look the way that we want. And so from here, it is running things until you get the, you know, the theme of your dreams.
And so there's a few ways of doing this, but if you enter the command palette again, and then hit debug, select, and start debugging, and then extension, this is going to open up as if our extension, like, truly, truly exists, and we have it installed and everything like that. And in this case, it would show us what the theme actually looks like. And so in this case, we can see it actually looks pretty good, right? Like, in terms of, like, what, you know, I might want this Ally Dark theme for Positron to be. But from here, this is kind of where you would start tweaking and everything like that. So my recommendations for that is, like, change, you know, start changing things. And when you save, there we go.
If, when you save things, things will update here. So say, like, editor background is this color. Let me know if my code is too small, too. I can see it. Okay, great. So editor background, so I'm going to change it to FFF, which is white, and I can see very clearly, like, oh, that's what that, you know, what editor background means. I don't want it to be white. So I'm going to switch it back. And you could just go back and forth until you get, again, exactly the theme that you want. And another thing that AI specifically clogged code for is if you don't know the name of a particular part that you want to change, you could just ask it. So, for example, I, if you, if you look back at RStudio, you know, this active tab is this darker color, right? And so let's say that, you know, I want my active tab here to also be that similar color. I just asked Claude, like, what is the name of that setting? And I have a little cheat sheet here, but it's called tab active background. And so if I add that in, right, and from here, I can, like, change this color. And a nifty thing about Positron is if you hover over the color, it'll give you this color picker, where you can actively change the color to whatever that you want.
Whoa, whoa, whoa, whoa. Can you show that one more time?
I did not know this, and I got happy to make my own theme.
So you just hover over, don't click, just hover over the hex code, and then it pops up this color picker where you can, you know, change your shade, change the color, right? And it just pre-fills your hex code in there. Yeah, exactly. And then the preview updates as well, so you can see exactly what it looks like. So if I hit save, save now. Oops, I don't have my other folder. There we go.
There. So we can see, indeed, the tab, the active tab now is that green that I chose, and then I can keep, like, editing. I actually want it to be, like, this dark color, so then save. And then you just go back and forth until youโ
We had a collective mind blow moment right there, so sorry I didn't want to stop you. That was amazing. This is the importance of pair coding, y'all. Code with other people, they will do things, click things, and hit keyboard shortcuts that you have never used before. And for them, they're like, yeah, this is just the way it works. And for you, your mind is blown.
This is the importance of pair coding, y'all. Code with other people, they will do things, click things, and hit keyboard shortcuts that you have never used before. And for them, they're like, yeah, this is just the way it works. And for you, your mind is blown.
Publishing the theme
That was awesome. Yeah, and just to kind of wrap up, so again, you can go back and forth, edit your theme until you get the one that you want. You can install extensions locally, but there are other ways of sharing if you want to share to, like, the broader world. So there's VS Code Extension Marketplace, and that's specific to VS Code. And then there's an open VSX Marketplace, and that one is for, I believe, all VS Code-based editors like Positron.
And so if we head on over back to the blog post, we actually, like, barely go into it. Like, here we go through, like, the specific settings and everything that we changed. And once we were ready, then the VS Code actually has very good documentation on how you can publish this into the different marketplaces. You publish to VS Code first, and then open VSX, and then from there, it's like, this is what the page actually looks like if you go. And it has, like, basically it reflects whatever you have in your readme, like, any images and things like that. People can download it from here if they want, and everything. And it's nice, too. It, like, tracks how many people have downloaded it. And, you know, as you make changes, this updates as well. I know, like, a big question folks ask is, like, how do I know an extension is good to download? One of the metrics you can see is, like, the number of downloads, right? Of course, who published it? Like, this is my brother, you can trust him. Or the number of downloads and things like that.
Yeah, and so that was the story of how we did it. And the last little note that I wanted to mention is we created these tab sets to kind of, like, compare the different things that we changed. And this is actually a Quarto extension by Mikhail Kanlui. And if you click on it, like, this actually copies the color, and you can use, like, so that way you don't have to copy and paste the actual hex. You can just click that button. And I think it looks quite nice in a Quarto document. So, I'll share that as well.
Questions and community chat
Awesome. It does look amazing. Okay, we have two minutes left, and we have a couple of questions. Let's see if we can get them in here. Renato had asked, why Envim instead of Positron to build a Positron theme? Oh, I didn't know that was an option. So, that's very cool. I would love to see how that works. Also, having a brother who's, like, a software engineer probably, like, skews things towards software engineering tools a little bit, and you're just, like, I'm just going to do what I'm told for some of these things.
Notobeco had asked, does the editor background have transparency to see your desktop? I'm not sure exactly what this question is asking. But, like, could you set the transparency of a color? Because I know that you can share, you can put, like, two characters at the end of a hex code to change the transparency of a color. And so, that might just be a thing that you have to try and find out whether or not it works. I have a feeling that the whole background of the whole thing would just be black, and so you would just, you would just see black and not, like, through the application. I definitely haven't seen a theme that did that. I have to admit, if I wanted to try that, I would just ask Claude. I'm like, is this possible? Was it possible? Oh, no, I would ask Claude, like, if I wanted to try it out. Somebody try it and report back. Yeah, it's very good at finding settings.
And then Marcos had asked, so, it definitely does that color picker on hover thing for a CSS file. Do you know if it happens to work in other files? Like, does it work in a .R file or a .qmd file? R file, let's see. Maybe it has to be within, it might work within Quarto, quartile. Oh, yeah, it does. Yeah, very, very nice. All right, Marcos, there's your, there's your answer. Oh, and I see No Tobacco also shared, like, hey, you can give your degrees of transparency at the end. So, he shared one with a 50 at the end for 50% transparency.
Um, we had a bunch of great things shared as far as resources. Marcos shared a color picker for Mac. If you are not on the Discord, and you're just hanging out on Zoom, this is one of the reasons to be there, because everybody is so wonderful, sharing amazing resources and ideas. Okay, today was so much fun. We're at the top of the hour, so we definitely have to stop and say goodbye. Um, thank you so much for hanging out with us. I hope that you will show up next week as well. Thank you for hanging out, everybody. We will see you either on Thursday or next Tuesday. Bye, everybody. Thank you.

