Transcript#

This transcript was generated automatically and may contain errors.

Hi, I'm Lucy D'Agostino McGowan, and I'm excited to talk to you about designing randomized studies using Shiny. You can find me on Twitter at LucyStats, and you can find these slides at lucymcgowan.com slash talk. So the work I'm going to be talking about today was done in collaboration with students in my data science lab at Wake Forest University. In particular, Jonathan Trattner and Nuri Park, and you can find some of our other projects at dmds.lucymcgowan.com.

Okay, so I'm going to show you four ways we can leverage the power of Shiny to help streamline our randomized study design via informed consent, randomization, collecting demographics, and incorporating learnr modules.

So informed consent. Informed consent is a common process when involving human subjects in a trial. Often you hand people a piece of paper, and they either say that they agree to be in a study or they don't. And so instead of that, we can actually have the entire process completed online from the comfort of your participants' browsers. And so we're basically going to leverage Shiny such that if the user consents, they're sent to the study. And if they don't, then they're sent back to the homepage.

And so in Shiny, we often work with two components, the user interface, what the user sees, and the server, what runs behind the scenes in R. And so here's some code for the user interface to be able to incorporate the consent here. And so first, you can incorporate the consent text via an HTML document, for example. And then you can use an action button function to create a nice action button that will either send the participant to the study if they agree, or back to the homepage if not.

So on the server side, we need to check whether the user clicked yes or no, and then send them somewhere accordingly. And so this function will check if the user clicked yes, and if they did, it's going to open a new window and send them to the link. I'm doing this using render UI, so I need to make sure to update the user interface with that UI output so that this actually works. And so that's what this is doing here, this UI output. And then OpenStudy was the ID that I gave that output in the server. So now that will actually send them to the link.

Randomization

So one of the coolest things about using Shiny for this is that it gives you the power of R from the web browser. So we can actually randomize participants at the time of consent. So it basically really streamlines that process. So we just need to update the server a little bit to do that. And so essentially what I've done here is I've added a coin flip to determine which group the participant should be in. And then they're sent to a different link accordingly.

So one of the coolest things about using Shiny for this is that it gives you the power of R from the web browser. So we can actually randomize participants at the time of consent.

So we're developing a package in R that does this and a few other neat features like generates user IDs, saves a randomization list, allows for unique links for users, etc. It's very much under development, but you can find it on GitHub at jdtrat.com.

Collecting demographics with Shiny Surveys

Okay, so now that we've randomized folks, let's collect some demographics. So we have another package called Shiny Surveys that can help with this. And this one actually is almost ready for prime time, so I encourage you to try it. You can install it from GitHub at jdtrat.com. And so basically what this package allows you to do is it lets you pass a data frame with questions, options, input types, dependencies, etc. And a nice shiny questionnaire is going to be generated for you that can then be incorporated in your application.

And so in R, it's as easy as just loading the package and then using the survey output function in the user interface, passing the data frame with your questions in it. And so here my data frame is called D. And then using render survey in the server function, and this will, you also will pass it that same data frame, and this will automatically generate a nice survey. It'll look something like this, where it has the questions as well as the different places to input. You can have required questions with those little stars. You can also have dependencies. For example, if you answer a certain way, then new questions can pop up accordingly.

Incorporating learnr modules

So finally, all of this can be incorporated in commonly used shiny tools like learnr modules. So for example, learnr modules can record all of the user's input data, which can be great for a study. And you can stick the user IDs generated from the task designer package in here, and then you can save this data with a unique ID that can be linked to the demographic data for later analysis.

So finally, all of this can be incorporated in commonly used shiny tools like learnr modules. So for example, learnr modules can record all of the user's input data, which can be great for a study. And you can stick the user IDs generated from the task designer package in here, and then you can save this data with a unique ID that can be linked to the demographic data for later analysis. So that's all. You can find me at LucyStats on Twitter. Thank you so much.