
Create a PydyTuesday Shiny app with Shiny Assistant
Watch Sara Altman quickly prototype a Shiny app for PydyTuesday with Shiny Assistant, an AI-powered tool designed to help you with Shiny. Shiny Assistant can create Shiny apps from scratch, debug or assist with existing apps, and answer general questions about Shiny. Shiny Assistant: https://gallery.shinyapps.io/assistant/ Learn more: * Shiny for Python: https://shiny.posit.co/py/ * The potential for AI-powered Shiny app prototyping with Shiny Assistant: https://posit.co/blog/ai-powered-shiny-app-prototyping/ * TidyTuesday project: https://github.com/rfordatascience/tidytuesday * Posit PydyTuesday GitHub repo: https://github.com/posit-dev/python-tidytuesday * Other videos in this PydyTuesday playlist: https://youtube.com/playlist?list=PL9HYL-VRX0oSDQjicFMLIIdcLv5NuvDp9&si=i09_CuKmjiV86D-9 #pythoncontent
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
In this video, I'll walk through the process of using Shiny Assistant to quickly prototype a Shiny app that uses TidyTuesday data. TidyTuesday is a weekly social data project. Each week, the TidyTuesday team posts a new dataset to their GitHub repository. You can then explore the data and post your visualization, model, dashboard, app, etc. to social media to share with others.
In collaboration with TidyTuesday, Posit hosts PydyTuesday, an initiative to help people get started with TidyTuesday and Python. You can check out the other videos in this playlist to learn more.
Today, I'll demonstrate one task you might want to do with the TidyTuesday data, create a Shiny app. And I'm going to do so with the help of Shiny Assistant, an AI-powered tool designed to help you quickly build Shiny apps. You can think of Shiny Assistant like a knowledgeable colleague ready to help you with Shiny.
Exploring the TidyTuesday data
Okay, so let's get started. Before I start building the Shiny app, let's take a look at the TidyTuesday data. So this is the TidyTuesday GitHub repository. This is where you can find each week's dataset. I'm going to scroll down to find the link for this week's data.
This week, we have data on emergency room wait times in the United States. Here we can see how to read in the data with R and Python. And then you also have a data dictionary. So I'm just going to quickly look at the data dictionary to identify what aspects of the data I might want to display in my Shiny app.
So I'm noticing that there is a state variable, a condition for which the patient is admitted, and some dates. So one thing you might want to do is visualize wait times for different conditions across states. Okay, so now we're ready to head on over to Shiny Assistant.
Building a prototype with Shiny Assistant
Okay, so this is Shiny Assistant. It's available for both Shiny for R and Shiny for Python. Over here, you can ask Shiny Assistant questions about Shiny, ask it to build a Shiny app for you, or ask it to debug an existing Shiny app that you have.
We're going to use Shiny Assistant to build an app that uses this week's TidyTuesday emergency room data. But before I give Shiny Assistant the actual TidyTuesday dataset, I'm going to have it build an app just conceptually about emergency room data, just to get something simple working, so I can visualize what I might want out of the Shiny app for this week's data.
So here's the prompt I'm going to ask. I'm asking it to create a basic Shiny app with a sidebar, where there's one input where the user can select a variable to visualize, and then on the main part of the app, there's a visualization. And then I'm saying just to create fake emergency room data. I could supply it with the TidyTuesday data right off the bat, but I want to sort of force Shiny Assistant to make something as simple as possible before we're using the real data, which has a lot going on in it.
Okay, and then I'm saying just make the app as simple as possible. So I want something that's easy to understand, so that when I take that code and start development on my own, I know what's going on and there hasn't been anything done that's unnecessarily complicated.
Okay, so Shiny Assistant is generating the code over in the chat on the left, but then also opening Shiny Live app, creating an app.py file, and then placing the code in that app.py file and running the app. So we can see the app that it made over here. So it does have, like I asked, an input with different metrics to visualize, and then it visualizes those in the main content area. Great, so this is pretty much what I asked for. It's a pretty simple app, but it's easy to understand.
Using the real TidyTuesday data
So now we're ready to ask it to use the real TidyTuesday data. So now I'm going to say, can you use the real data and provide it with the link. And then behind the scenes, I took a closer look at the data and I realized that it's in a long format. So there's a condition column, which stores information about where the patient was and what kind of care they were getting. So some of the values of condition are emergency room, but some are like sepsis care or vaccination.
And then there's a measure ID column and a value column or measure value column or something, where measure ID contains different things that you're measuring, like wait time or maximum wait time, and then the value stores the actual value of that measure. So it's in a long format. So I'm just going to give Shiny Assistant that extra context.
Okay, so I want it to only use rows where condition is emergency department, and then I'm giving it some extra information about the columns. I think this is actually measure ID column. And then I'm also going to give Shiny Assistant the data dictionary. So I just copy and pasted this from the TidyTuesday repository.
So it was a lot of information for Shiny Assistant, but we are using real data that I haven't explored that much. So I just want to give it as much context as possible. Okay, so it made us a new app, but we're getting an error. So one really nice thing about Shiny Assistant is that I can just feed it back this error and have it debug it itself instead of trying to do it on my own.
So let's see what it says. It's going to regenerate hopefully working code and then rerun the new app. Great. Okay, so this time it worked. And see, now we're using our actual TidyTuesday data. We can select different metrics that are tracked for the emergency department, and that's visualizing that metric for all of the states. So this is basically what I asked for. It doesn't look great right now, but we can keep iterating on it.
Iterating on the app
So I'm going to see what happens if I ask Shiny Assistant to make some changes. So let's say I only want to visualize the data for a certain amount of states. This is kind of a lot of states for one plot. I can't really see their names. I could try to fix that, but maybe I'm only interested in a handful of the states. Let's ask it to add an input for the states.
Okay, so I've asked it to add a selectize input so that the user can select which states they want to visualize. Okay, great. So this is already easier to see. So I can add states and or remove them, and now the user can select both the metric that they want to see and the states that they want to see that metric for.
Okay, so this is a great start to a Shiny app. It's not super polished or super finished, but Shiny Assistant helped me get to a working, useful Shiny app very quickly, and I now have a great starting point for continued development.
Shiny Assistant helped me get to a working, useful Shiny app very quickly, and I now have a great starting point for continued development.
So I could either continue working on this in Shiny Assistant or I could take this code to my local IDE and continue development there.
Asking general questions about Shiny
One other thing I want to point out is that you can ask Shiny Assistant just general questions about Shiny or about your app. So let's say I want to understand something that's happening in the app. So maybe I want to just know more about the selectize input. I can ask Shiny Assistant, and it'll just give me some more information, and it also knows about the code that I'm writing, so it can tell me specifically what's happening in my own code that it just wrote for me. So this is really helpful for learning more about Shiny as you're developing Shiny apps.
So I encourage you to check out Shiny Assistant, whether for TidyTuesday, PydyTuesday, or some other Shiny app that you would like to work on. It's really helpful for quickly developing and iterating on Shiny apps as well as for just learning more about Shiny.

