Resources

Evangeline Reynolds | Flipbooks | RStudio (2020)

Good examples facilitate accomplishing new or unpracticed tasks in a programmatic workflow. Tools for communicating examples have improved in recent years. Especially embraced are tools that show code and its resultant output immediately thereafter --- the case of Jupytr notebooks and Rmarkdown documents. But creators using these tools often must choose between big-picture or narrow-focus demonstration; creators tend to either demo a complete code pipeline that accomplishes a realistic task or instead demonstrate a minimal example which makes clear the behavior of a particular function, but how it might be used in a larger project isn't clear. Flipbooks help address this problem, allowing the creator to present a full demonstration which accomplishes a real task, and gives the viewer the opportunity to focus on unfamiliar steps. A set of flipbook building functions parse code in a data manipulation or visualization pipeline and then build it back up incrementally. Aligned superimposition of new code and output atop previous code and output makes it easy to identify how each code change triggers changes in output. The presentation will guide attendees in creating their own Flipbooks (with Xaringan slides) or mini Flipbooks (gif output)

image: thumbnail.jpg

Transcript#

This transcript was generated automatically and may contain errors.

Hi everyone, sorry, my name is Allison Hill. I'm a data scientist and professional educator at RStudio. Welcome to Learning and Using with R. Our first speaker is Gina Reynolds.

Hey, good afternoon. Yes, my name is Gina Reynolds, and I'm here to talk to you today about flipbooks and a new package for creating them called Flipbook R. Just a little bit about me. I teach at the University of Denver in the Corvell School of International Studies, and I co-organize Denver R-Ladies. I tweet at Ava Mae Ray. I also write code on GitHub. I'm avamaeray there, too. And I used to do quite a fair amount of blogging on Netlify, but I've been recently writing a lot more flipbooks.

So just as a traditional flipbook allows you to watch the evolution of a scene, our new code flipbooks allow you to watch the evolution of a code pipeline. So formally, flipbooks present code and output side-by-side and step-by-step, and they deliver to you something that's like a stop-action movie based on looking over the shoulder of somebody that's actually building up a coding pipeline and taking snapshots at appropriate moments, like they're checking their code, checking their work along the way and intermediate outputs.

Origins of the flipbook project

So I think to understand where we are with the project right now, it might be useful to look back in time to look at the origins of this project. And I'd say that in 2018, we were in the era of the proto-flipbook. So Garrick, Aidan, Bui, and I and Emi Tanaka were all interacting with this idea of presenting code and output side-by-side and building it up incrementally. But at this time, the project that the projects that we were building were very handcrafted and artisanal. So we were all crafting each slide that composed each mini-flipbook one-by-one, using a lot of copying and pasting.

But I was excited to find these like-minded people, and so I approached them. They seemed to know a lot about the tool that we were building with Sharingan, and I asked them, do you want to build flipbooks together? We were all circling around this idea. We thought the flipbooks could really deliver great experience to users, deliver them a lot of insights about what's going on in a code pipeline. But to really reach flipbooks' full potential, we realized that we had to move away from this copy-paste modality. We had to move to something that unburdened the creator of flipbooks.

So we moved to automation. So now we're automatically parsing a block of input code and automatically reconstructing code into partial builds, and then automatically delivering these partial builds onto a presentation platform.

2019 was a year of exploration and refinement. We were interested in how we could use this new tool, different modalities to use it, using other people's code, breaking the flipbook building code that we had developed. And in 2020, you can build a flipbook in five minutes with flipbook R, which is a development package on GitHub, using Sharingan as well.

Live demo: building a flipbook

So we're going to do just that. We're going to build a flipbook in five minutes. But first, a little bit of background. We're going to use ggplot2 in the demo, but we're going to use a dialect of ggplot2 called slow ggplot. And slow ggplot2 is literally only the wonderful ggplot2. So everything that we're going to be doing is native to ggplot2 and fully supported. It embraces incrementalism and feedback. So for every decision that you make, you're going to want, when possible, to have one ggplot statement.

So you may be familiar with more this way of going about creating a ggplot, where you have a statement where your data is defined and your aesthetic mapping. And then you say what geometric object you want to take on those aesthetics. And then say what labels you want. Contrasting this with slow ggplot, we start with data. Pipe that into a ggplot statement. Move to declare our X position aesthetic, our Y position aesthetic, our geometric object. And then we can move to non-required aesthetics. And the label statements will make each of these decisions get their own ggplot statement.

So the behavior that we're going after then will look like this. We've got our code on the one side and output on the other. Okay. So let's begin our live demo.

So delivered to you with a package is a template. So we can open that up by going to our markdown. And then from template, you'll grab a minimal flip book.

And we're going to keep the YAML. And basically this will walk you through a lot of modalities that I'm going to talk you through earlier. So I'm going to just delete most of the contents. And just keep the last code chunk, which is CSS. This is going to allow you to adjust the code font size pretty easily. Okay. And then I'm going to include a code chunk. We're going to use the tidyverse. And of course flip book R.

Then I'm going to add a slide break. Three minus signs. No space. And we're going to start building our code pipeline. So I'm going to just use the cars dataset. Pipe that to ggplot. And we can check our code as we go.

Add the aesthetic mapping. I'll have X represent speed. And Y represent distance. And then add my geometric object. And let's just do some multiple mapping for fun. We'll have color also represent speed.

Okay. So this is our source code chunk. And we don't actually want it to appear in the flip book. So we're going to set the code chunk option include to false. And then we're going to refer to this code chunk with a name. I'm going to call it cars. And then we'll use the flip book function chunk reveal to reveal this coding pipeline.

So the first argument here is the chunk name. That's cars. And we're all set to build our flip book. So I'm going to hit knit here in RStudio. Save this as the flip book. And you can see that the build is happening. And you've created your first flip book.

Break types and display options

So what's going on is I'm using actually the auto mode of display. So what's being looked for is balanced parentheses. And these are good places to take breaks along this coding pipeline. But you can also use the argument break type and set that to user. And with a special comment break in capital letters. You define where you want breaks along this pipeline. So let's just have a quick look at that.

So two break points. Okay. So I'm going to go ahead and create a new break point. Two break points. Okay. So I'm going to present to you a few more modalities that you can use.

An additional one is setting the break type to nonsequential. So this could be used in a context where you want kind of this behavior for something to appear within your pipeline. But not right away. So here I would use that nonsequential setting and then set the break to here break and then the number two and then break three here. We can also set the break type to integer. And you might think of this as like entering the multiverse where you want code to be revealed multiple times just the same code. And this would be appropriate in a setting where you're doing some sampling. Taking a random sample. So here I'm sampling with replacement. Sample fraction. Replace equals true. We have these multiple realizations of the same code.

You can also set the argument display type. So the default is to display both the code and the output side by side. But you might want to display just the output. So maybe in a more traditional setting, in a presentation setting where you just want to slowly present each component of a plot. You can also set display type to code. Just display the code. Maybe with students thinking about what their expectations are as you build up a plot.

You can also tell longer stories with lip booking. So you might use a source code chunk and do some wrangling steps and then create an object within that code chunk and then have another source code chunk where you're doing some plotting. So that would look something like this. I created cars mod. And then working from there, I pipe into a plot. So you noticed that I used right assignment here. And you might be asking yourself, well, can I use left assignment? And flip booking allows for this too. And you just set the parameter left assigned to true. And what we do then is track the first object that you create in your code chunk and print it at the bottom of the flip book.

And you can use flip booking beyond the tidyverse as well. For example, with this modality where you kind of chain by overriding an object. So here you would set left assignment to true again. And you can also use brackets and logical indexing by using this dot bracket syntax with the McGridder pipe. That would look something like this. And you can use flip booking with base R plotting too.

Why flipbooks are worth it

Okay. So we've shown you that you can build a flip book pretty easily. But it does take a little bit more effort. So you may be asking yourself, is it worth it?

And I would argue that it delivers a lot of insights to newcomers when they see a long pipeline of code. I think that maybe the message is something like this. And even for more seasoned practitioners, I would say that an unfamiliar code within a long pipeline, it may be possible for them to infer what must be going on with that code. But I do think that this might require a lot of mental gymnastics.

So, what does flipping do for us, though? Right? So, we're showing all these intermediary steps. But we could show them by infinitely scrolling through the steps. The question I'm asking is what does temporal offset afford rather than spatial offset?

So, this is the example of spatial offset. We could scroll through the different states. But spatial offset requires us to engage in visual search, which requires focused attention and concentration. You've probably experienced this.

But with flip books, you're delivered this blink comparator type experience, where you observe different states superimposed and aligned.

But with flip books, you're delivered this blink comparator type experience, where you observe different states superimposed and aligned.

And this is a blink comparator. It was used to super align images of the night sky at different points in time. And it's credited for the discovery of Pluto. We found Pluto several decades earlier than we would have otherwise.

Motion detection makes discovering differences easier.

Conclusion and thanks

To conclude, I would say that flip books has a lot of potential in educational settings. But also for reference, you might if you're using a pipeline frequently, but not frequently enough to recall all of the steps, you might make a flip book out of it and come back to it in the future. And also, for communicating what you're doing with colleagues and peers.

I also think that flip books might be useful in creating greater transparency. Because what API we're using shouldn't make people feel like outsiders. It should be clear what's going on, no matter what pipeline we're using. So, I want to issue a big thanks to Garek and Emi Tanaka for helping get this project off the ground. And I'm also really grateful to a lot of critical infrastructures that make the project possible. To testers for their code review. And to volunteers. Many of them from Tidy Tuesday, the initiative. To see what would break flip booking. And to support at the University of Denver. That's it.

Q&A

So, we have a few questions. And we have a little bit of time. There's the timer. So, our first question is, can you use chunk underscore reveal within a markdown document, like a blog down page, a markdown report, et cetera, so the flip book works like a GIF instead of a slideshow?

So, at this point, no. So, the output that you get is like a full website. So, it's the output that sharing gives you, which is the full website. We are looking at different modalities, different presentation platforms that we could use. So, one of the things that we're working on is just delivering a GIF. So, using actually combining images. So, that might be coming up. Yeah.

And then one more question. When do you expect Flipbooker will be on CRAN? May, I guess. No promises.