
Colin Rundel | `livecode`: broadcast your live coding sessions from and to RStudio | RStudio (2020)
In this talk we will demonstrate livecode, a new R package for broadcasting code for live code demonstrations. This package implements a simple webserver (using httpuv) to dynamically publishes the content of a code file (i.e. .R or .Rmd) as you edit it live. This enables your students to have near realtime access to your code as you write it. The broadcast file can be viewed with any webbrowser but the package is specifically designed to be used within RStudio leveraging its builtin viewer. This gives students have direct access to the shared code within the IDE, allowing direct copying into their own source files and/or the console and thereby improving their ability to interact and experiment with your code. A 5-minute presentation in our Lightning Talks series
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
Okay, thank you all for being here. So I'm just going to present a little bit about a package that I've been working on over the last couple months called live code.
So I teach a lot of statistical programming classes to a variety of different student levels and one of the tools I've been adopting more and more in my teaching is this idea of live coding. And these are a couple quotes from some academic papers from the computer science literature about what is live coding. I think we all probably have a pretty good idea, but I think one of the key things at least coming at it from an educator's perspective is this idea of when we're teaching people to code, one of the things we want to do is show them the thought process. So we don't want to just show them finished code, we want to show the process of generating code and also talk about and narrate the thought process that goes into solving that kind of thing.
And I think this is a really important powerful tool and I've been sort of using it more and more in my teaching. But this is sort of in conflict with another sort of big idea within pedagogy, which is this idea of active versus passive learning. The general preference is we want our students to be doing active things, engaging things, doing stuff with their hands, that kind of idea. Live coding is sort of inherently passive. They're sitting there watching you code things and they're listening to what you talk about and in the little bit where it tends to be active, it's active in not a great way. The students will sit there and they'll type the same code that you're typing, they're repeating that same effort, and then they're not listening to what you're saying, which is sort of the most valuable thing that's going on here.
they're repeating that same effort, and then they're not listening to what you're saying, which is sort of the most valuable thing that's going on here.
So live code is sort of an effort that I'm trying to make to move some of this stuff away from sort of just purely passive, absorbing that information into a more active learning kind of thing, and particularly leveraging RStudio in this interactive environment to get them playing around with code to explore it and learn it in that way.
Screencast demo
So this is a screen cast of the package. Reload it so it launches. So live code has a lot going on. Don't worry about the code right now. It's just running one function called serve file. What it's doing is it's looking at the file that I currently have open in RStudio, launching a server, making that available, and what it's doing in real time or close to real time is syncing the contents of that file in my RStudio session to a webpage that the students can go to and log in on.
So if you see this sort of little banner thing in the blue picture up in the upper right-hand corner here, what we see is that we're saying, welcome to live code. We're serving example.r at and then a bit link that they can connect to. All of this went by a little quick, so I'll play it again and try to narrate a little bit. So we launched the server. It figures out from the context what it should be doing, figures out my local network environment, and I get this server running locally, but that link should now be accessible to other people. They can click on it, connect, and so here I'm just demonstrating it by two sessions that are running simultaneously, and the idea is I should be able to scale this up to 50 or 100 or even 200 students.
Other things, we see that we get syntax highlighting, note as I make changes in the file in RStudio, that change is propagating over to the session in the web browser, and other sort of nice quality of life things like if we look at the line that's highlighted in the web server is the same thing where my cursor is in the file in RStudio, so we're trying to sync all of this kind of stuff.
There's a lot of things going on behind the scenes here, but this is really leveraging a lot of the powerful tools that RStudio has written for doing asynchronous programming, so if you heard Winston Chang's wonderful talk yesterday, we're doing all of that kind of stuff to make this sort of seamless, but the goal is to make this as accessible to educators as possible.
How it works
To give you a little bit more of an idea about what's sort of going on behind the scenes, this is the main function. This is mainly the thing that you should interact with, so before I ran it without any arguments, but it's using things from the RStudio API to figure out, okay, what file do you have currently open? I had a file called example.r, so it's picking that out for me and doing it. Other things like specifying the IP address that you want the server to run on. Most people who are probably going to use this don't want to know about running a server, don't want to know about IP addresses or ports, so one of the things that the package tries to do is figure that out for you automatically, so here it's using this 10.port.
If you know something about IP addresses, that's a private IP address, so this is actually from me running this on the hotel network here. That's not something that's accessible to the outside world. I can't do anything about that as a package maintainer, but I can at least give my users some information about that, saying, hey, you're on a private IP address, only other people who are on that same network will probably be able to access it. So again, trying to provide some feedback, tell you what's going on there.
Autosave, so again, this is trying to do this in a sort of nice, elegant way, so we can leverage RStudio to save the files automatically and then only push things to our users when we actually make a change, so we're not constantly pushing the same file over and over again. We wait for a change. When that happens, it gets sent out to everybody. Otherwise we don't do things, and depending on how big the file is and how many people you have connected, we can set that interval in terms of when it pulls things to be slower or faster, so I can send changes out every two minutes, so on and so forth, and we're playing with other kind of cool things, like sending messages to your users, that kind of thing, and it's very early days for the package, but we'd like you to play with it, try to break it, try to stress test it, that kind of thing, and let us know how it goes. There you go. Thank you.
